By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,199 Members | 1,724 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,199 IT Pros & Developers. It's quick & easy.

What is wrong with forward declarations in Managed C++?

P: n/a
Can anyone explain why C++ .NET compiler throws error for the following code

// Forward declaration of ListViewItemComparer class
public __gc class ListViewItemComparer ;

public __gc class CProgramLoaderForm : public System::Windows::Forms::Form
ListViewItemComparer* m_ListViewItemComparer ;

<Rest of the class definition goes here>
} ;

public __gc class ListViewItemComparer : public IComparer
ListViewItemComparer(void) {} ;

<Rest of the class definition goes here>

The error is:

error C2512: 'CProgramLoaderFormNamespace::ListViewItemComparer ' : no
appropriate default constructor available

If however I change order of CProgramLoaderForm and ListViewItemComparer
classes then everything is fine and compiler is happy. I can't keep this
order (ListViewItemComparer first and CProgramLoaderForm second) because then
stupid Visual Studio refuse to open the form in designer.

So my question is what is wrong with forward declarations in Managed C++?
Why compiler does not recognize ListViewItemComparer class?

Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

I can answer your question by directing you to Th
Tetris example has a raw form and namespace created that overcomes th
Interface problem. I have a question. The reason I don't want to answe
your question personally is because this same problem caused mor
complications for me but you might have an answer. If you have worke
with MDI forms, than creating a class in the same project outside th
namespace will create unified access by child forms and will lock out
forward declaration in the namespace. I accidentally fixed the proble
without declaring ::Form using the same Tetris example and it jus
worked in one compile. Don't do that if you want to be able to create
form project using the IDE and want to access class variables public o
otherwise (using get set methods, etc.). If you solve the proble
please post it. To recap the question. Create a new winform project g
to an mdi "app type" and add a class object. When instancing the clas
in the top form, access the class variables using any legal method an
it should work without forward declarations or __value, than using
duplicate declaration in the extended namepsace of the child form, i
should allow clean access as follows ..
TopForm::instanceClass->variable, from the child form. "Sometimes i
works sometimes it doesn't." obviously my error. I pushed the compile
and really confused myself. So I am trying to get that to work. P.S.
don't want to confuse you but forward declaration the way I made use o
the concept is to instance the object in the topform namespace just a
you would have to have a static managed type initialization in a __g
class. I understand it is not exactly the problem you have but th
syntax is extremely important and the Tetris example is an SDI app
that allows you to see the top form re-defined in each extension to th
namespace that is per source and or header file. Also P.S. your proble
in this way is having to access managed c++ functions to use CO
Interfaces :). It is not necesary if you do a 'clean' conversion t
__gc types. :). I hope it helps

k_brizs's Profile:
View this thread:

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.