开发者

Weird error using C++/CLI - Cannot convert from parameter type to same parameter type

开发者 https://www.devze.com 2023-03-30 15:12 出处:网络
I\'ve got the following code: vlib_stage_decoding_config_t Decoder::CfgTransform(const DecodingConfig config)

I've got the following code:

vlib_stage_decoding_config_t Decoder::CfgTransform(const DecodingConfig config)
{
    vlib_stage_decoding_config_t cfg;
    return cfg;
}

void Decoder::OpenDecode(const DecodingConfig config)
{
    vlib_stage_decoding_config_t int_cfg = CfgTransform(config);
    vlib_stage_decoding_open(&int_cfg);
}

Header file:

public ref struct DecodingConfig
{
};

I get the following error:

Error 1 error C2664: 'Video::Decoding::Decoder::CfgTransform' : cannot convert parameter 1 from 'const Video::Decoding::DecodingConfig' to 'const Video::Decoding::DecodingConfig' decoder.cpp

This is pretty nonsensic开发者_如何学Cal to me. Any ideas?


Try this:

vlib_stage_decoding_config_t Decoder::CfgTransform(DecodingConfig^ config)
{
    vlib_stage_decoding_config_t cfg;
    return cfg;
}

void Decoder::OpenDecode(DecodingConfig^ config)
{
    vlib_stage_decoding_config_t int_cfg = CfgTransform(config);
    vlib_stage_decoding_open(&int_cfg);
}
  1. const is meaningless for managed types.
  2. Despite your use of struct, DecodingConfig is a reference type, not a value type, so it cannot be passed without a tracking handle or a tracking reference. If you want DecodingConfig to be a value type, use value struct instead of ref struct and get rid of the ^s in your function arguments.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号