Max
Max

Reputation: 4405

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

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 nonsensical to me. Any ideas?

Upvotes: 1

Views: 1326

Answers (1)

ildjarn
ildjarn

Reputation: 62975

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.

Upvotes: 2

Related Questions