I'm having problems with specifying a "forward declaration". The class with it in compiles okay, but when the compiler meets a "gcnew xClass();" to instantiate an instance, the compiler "crashes" with a fatal error C1001h in compiler file 'mscl.cpp' line 1441.
my class starts -
using namespace System;
generic<class K, class V>
where K : IComparable
ref class xClass
ref struct bNode; //*** Needed to overcome the forward reference ***
ref struct kNode
kNode(K Key, V Value)
key = Key;
value = Value;
ref struct bNode
kNode^ rLink; //*** THIS LINE CAUSES THE CRASH ***
When I swap the struct blocks round its always the 2nd block's reference to the first block that causes the problem.
If I change the 'kNode^ rLink;' to 'Object^ rLink;' it compiles, but takes an age to do it! devenv.exe seems to go into a loop and lock up the system 100%. I've got to force the MSVC to via with ctrl-alt-del.
It seems that the compiler gets into an endless loop with this circular cross-reference. If I break it by removing either rLink in bNode, or dLink in kNode (and the forward ref line) the compier works okay.
is there a semicolon missing after "ref struct kNode" ?
EDIT: oh its a nested structure... you'd better add code tags
Last edited by memeloo; December 10th, 2010 at 10:11 AM.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
I've tried various ways to work around this problem. First I tried making my C++/CLI class into a dll, then calling it from C++ code. The class compiled, but the calling program failed to compile; the compiler crashed and offered to "phone home" to Microsoft with the error information. (like it did previously).
Next I tried to use this dll from C# code. This compiled okay but crashed at runtime. I get a runtime error of System.TypeLoadException. It seemed to instantiate okay but failed when it tried to access the methods in xClass.
So now I converted my class source into C#. C# will accept forward references without needing forward declarations. I compiled this into a dll.
This dll will run okay from a C# main program, but still fails to compile from a C++ main program.
It seems that the C++ compiler does not like mixing generics with forward references. This also shows that you can't write a dll in C#, have it run okay from C#, then expect to be able to use it from C++ as well.
I am still using MSVS from 2008, but like with the earlier 2005 version I'm getting frequent blue screen crashes. I am a bit reluctant to move up to MSVC 2010 - why are Microsoft having to make so many updates before they get it right?