Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 22 Jun 2005 21:46 GMT
Can anyone explain why C++ .NET compiler throws error for the following code
segment:

// 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
{
public:
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?

Thanks
k_brizs - 23 Jun 2005 02:51 GMT
I can answer your question by directing you to codeproject.com. 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_briz

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.