.net - Why do I get a conversion error when calling this from outside my class? -
I have a class that I am trying to write some unit tests, but I get conversion errors: < / P>
1> C: \ projects \ myproj \ unittests \ UnitTest_MyClass.h (60): error C2664: 'MyClass :: MyFunc': parameter1 is labeled as' Generic Collection :: Circle Buffer & lt; T & gt; ^ 'JennyColcons :: Circular buffer & lt; T & gt; ^ '1 & gt; 1 & gt; With [1 & gt; T = Constant MyPower :: Data Packet ^ 1 & gt; ] 1> And 1> [1 & gt; T = Maiprod :: Datapacket ^ Const 1 & gt; ] Class (just a snippet) under examination:
Public Reef Class MyClass {Safe: Double MyFunc (Generic Compilation :: Circular Buffer & lt; Const MyProj :: DataPacket ^ & gt; ^ Data, Int and First Index, Int, and Previous Index); Unit Test (only one snippet): [Test] Public ref class UnitTest_MyClass: Public MyClass {public: [test] zero test_0001_MyFunc () {Generic Collection :: Circular Buffer & lt; Const MyProj :: data packet ^ & gt; ^ Data = nullptr; // This will eventually populate the test data with int firstIndex = 0; Int lastIndex = Data-> Length -1; Double AnandSures = MyFunk (Data, First Index, Last Index); // Cause Error C2664}
I can call this method in the same way from within the classroom under test and it works fine, so why does it fail when I Telling it to the unit is an important statement missing from the questions, but it can be estimated:
This has failed to compile because you can import type definition through #include assembly instead of reference Are you expecting the unit he tested this code.
You must keep in mind that the keyword const is a problem, CLR does not completely miss the notion. This is only meaningful when it is implemented, this will not happen if your code is used by any other managed language, like VB.NET or C #. There is no such thing as the language in which any thing like const is used in the original C ++.
Metadata in CLR uses a language variable and parameter type [Modopt] through the C ++ / CLI compiler using it when it exits the metadata for the funk; & Gt; Some, which you can see with ildasm.exe:
MyFunc (Class Generic Collection. Cricker buffer `1 & lt; class DataPacket modopt ([Mscorlib] System.Runtime.CompilerServices.IsConst )> Data, // etc ... Fit to fit, focus on the type parameter [modopt] emitted though it is not enough to express completely different ways in which const can be implemented in the original C ++. Data argument const T ^ data , T ^ data console A const T ^ data console is nothing that can only be expressed with a single [modopt]. You can argue that this is a compiler error , But this is not really, this restriction was intentional. They have made enough compilers to ensure that const is ambiguous here and generates a suitable error message.
< P> Well, you can not do a lot about this. If you include the definitions of the words, then this will not be a problem, then the compiler knows enough about the declaration. Maybe you can retrieve your project, though it is not practical at all. My always advice with this problem has left the notion that const is useful in managed code. It is not that C ++ / CLI is an interpictable language and the general consumer of this kind is called Cons And so it will not be implemented.
Comments
Post a Comment