Forward Declaration and no appropriate default constructor
-
Hi Mark, It seems I have been providing the fun here, I suggested Buck to look into my Sokoban article for printing, but then that's in C# and does not know about circular reference problems... :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
It gets worse when you start using Generics in C++/CLI in this situation! :((
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
It gets worse when you start using Generics in C++/CLI in this situation! :((
"We make a living by what we get, we make a life by what we give." --Winston Churchill
Hi George, thanks for the warning. I haven't used generics much yet, no problems so far... :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi George, thanks for the warning. I haven't used generics much yet, no problems so far... :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
I guess you know how to keep yourself away from big issues; however, I don't. In certain situations, even with formal coding techniques, the compiler will still view your class (with a base clase of
Foo
) as a basic ref class with just a base class ofObject
. The only way I was able to get the code to compile was to create anIFoo
generic interface and made Foo a Template class. Geo"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I guess you know how to keep yourself away from big issues; however, I don't. In certain situations, even with formal coding techniques, the compiler will still view your class (with a base clase of
Foo
) as a basic ref class with just a base class ofObject
. The only way I was able to get the code to compile was to create anIFoo
generic interface and made Foo a Template class. Geo"We make a living by what we get, we make a life by what we give." --Winston Churchill
That's interesting. There's a bug where the C++/CLI compiler won't recognize that a managed array implements System::Array. The result is you can't pass a managed array to a function that takes an argument as IEnumerable^ or something similar. What you're saying makes it sound like this bug might just be a more specific case of a general problem the C++/CLI compiler has with generics. Unless I'm misunderstanding you.
-
That's interesting. There's a bug where the C++/CLI compiler won't recognize that a managed array implements System::Array. The result is you can't pass a managed array to a function that takes an argument as IEnumerable^ or something similar. What you're saying makes it sound like this bug might just be a more specific case of a general problem the C++/CLI compiler has with generics. Unless I'm misunderstanding you.
iddqd515 wrote:
There's a bug where the C++/CLI compiler won't recognize that a managed array implements System::Array. The result is you can't pass a managed array to a function that takes an argument as IEnumerable^ or something similar. What you're saying makes it sound like this bug might just be a more specific case of a general problem the C++/CLI compiler has with generics.
I don't know if what I said applies to that. Nevertheless, translating C# code to C++/CLI may require some extensive hoop jumping. On the other hand, with the help of templates and other C++ idiosyncrasies, you can write code not possible in C#. Since I don't currently have time to write articles, I have been posting in my blog on Code Project some C++/CLI code and brief comments. I will be adding some code on this as soon as my wife allows me to. Any, any comments good, bad or indifferent are welcomed. -- modified at 10:57 Tuesday 21st August, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
iddqd515 wrote:
There's a bug where the C++/CLI compiler won't recognize that a managed array implements System::Array. The result is you can't pass a managed array to a function that takes an argument as IEnumerable^ or something similar. What you're saying makes it sound like this bug might just be a more specific case of a general problem the C++/CLI compiler has with generics.
I don't know if what I said applies to that. Nevertheless, translating C# code to C++/CLI may require some extensive hoop jumping. On the other hand, with the help of templates and other C++ idiosyncrasies, you can write code not possible in C#. Since I don't currently have time to write articles, I have been posting in my blog on Code Project some C++/CLI code and brief comments. I will be adding some code on this as soon as my wife allows me to. Any, any comments good, bad or indifferent are welcomed. -- modified at 10:57 Tuesday 21st August, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I forgot to read what I posted. I meant a function with an argument of the generic interface IEnumerable^ not IEnumerable^. That's what prompted me to connect your problem with that bug. I'm about to try fiddling with it.
Visit my blog. I did address something about that and it may or may not be helpful: http://www.codeproject.com/script/profile/whos_who.asp?id=207715[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
Visit my blog. I did address something about that and it may or may not be helpful: http://www.codeproject.com/script/profile/whos_who.asp?id=207715[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
Interesting stuff, but I'm not sure its quite along the lines I'm looking for. Do you have a code example or solution that demonstrates the problem where the compiler doesn't recognize the proper base class of the derived class and just thinks its a System::Object?
-
Interesting stuff, but I'm not sure its quite along the lines I'm looking for. Do you have a code example or solution that demonstrates the problem where the compiler doesn't recognize the proper base class of the derived class and just thinks its a System::Object?
Yes I do. I will try to post it as soon as I get time! Also, the problem you refering to is something like the following where I have to use a
safe_cast
to get it to work:using namespace System;
using namespace System::Collections::Generic;generic <typename T>
void Foo(IEnumerable<T>^ col)
{
for each (T val in col)
{
Console::WriteLine(val);
}
}int main(array<System::String ^> ^args)
{
array<int>^ arr = {10, 20, 30, 40, 50};Foo(safe\_cast<IEnumerable<int>^>(arr)); return 0;
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
Yes I do. I will try to post it as soon as I get time! Also, the problem you refering to is something like the following where I have to use a
safe_cast
to get it to work:using namespace System;
using namespace System::Collections::Generic;generic <typename T>
void Foo(IEnumerable<T>^ col)
{
for each (T val in col)
{
Console::WriteLine(val);
}
}int main(array<System::String ^> ^args)
{
array<int>^ arr = {10, 20, 30, 40, 50};Foo(safe\_cast<IEnumerable<int>^>(arr)); return 0;
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
yeah that's exactly the problem. Alternatively you could call Foo(arr). The C# compiler properly recognizes that an array is System::Array so it doesn't require that cast. I don't believe there's any way to dynamically get the generic type argument with typeof or GetType(). It seems this would make it quite difficult to use generics dynamically based on user input or something similar.