473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
Nov 17 '05 #1
1 2295

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
-----------------------------------------------------------------------
k_brizs's Profile: http://www.msusenet.com/member.php?userid=255
View this thread: http://www.msusenet.com/t-187055783

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
6
by: Steven T. Hatton | last post by:
Should I be able to forward declare something from a namespace different from the current one? For example the following code compiles: //testdriver.hpp #ifndef TESTDRIVER_HPP #define...
35
by: GTO | last post by:
I do not believe that C# is the future of C++. I also do not believe that adding two thousand new library functions to the standard library is the future of C++. But what is the future of C++? Is...
3
by: Libertadrian | last post by:
Hi again, Maybe I missed something, but I cannot do a forward declaration in managed C++. By doing: namespace Namespace {
1
by: Gustavo L. Fabro | last post by:
Greetings! Going directly to the point: myclass.h: //-------------------------------------- #pragma managed //Forward declaration
2
by: Neo | last post by:
Hi, I am new to C++ and want to know what are forward declarations and any site which has a good introductory explanation. thanks in advance, nick
2
by: Carlos Martinez Garcia | last post by:
Hi all: I usually make forward declarations in headers. Something like this: class MyClass; Now, I need a reference to a type defined like this (traditional C Style): typedef struct {
25
by: raylopez99 | last post by:
First in an occasional series. I'm somewhat experienced in C++, and am using .NET Visual Studio 2005 as the IDE. I'm learning C#. What I don't like about C#, compared to C++ (all flavors): ...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.