473,387 Members | 1,722 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,387 software developers and data experts.

Forward declaration in Managed C++

I have a managed class A and inside A, I'm declaring an object of class
B. B has been forward declared.

Namespace X::Y::Z
{
__gc class B;

__gc class A
{
public:
A()
{
B *b = new B();
}

};

__gc class B
{
public:
B( )
{
}
};
}

The compiler complains
'X::Y::Z::A::B' : no appropriate default constructor available

Any clues??
Thanks
shree


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
2 2441
shree,

I have a managed class A and inside A, I'm declaring an object of class
B. B has been forward declared.

Namespace X::Y::Z
{
__gc class B;

__gc class A
{
public:
A()
{
B *b = new B();
}

};

__gc class B
{
public:
B( )
{
}
};
}

The compiler complains
'X::Y::Z::A::B' : no appropriate default constructor available

Any clues??

First of all, this is not the appropriate group for these questions.
Instead, try the microsoft.public.dotnet.languages.vc group (followups set
accordingly).

As for the answer: the compiler is right. The problem is that you're
defining A's constructor inline, so at the point you're using B::B(), it has
indeed not been defined yet. Remember that C++ does compilation pretty much
module by module.

Obviously, the easy answer is *not* to define A::A() inline....
--
Tomas Restrepo
to****@mvps.org
Jul 19 '05 #2
Thanks for the reply Tom.
And sorry about posting it in the wrong group.

-Shree

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3

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

Similar topics

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...
3
by: Michael Sgier | last post by:
Hello with the original code below I get the error: "forward declaration of `struct CPlayer'" class CPlayer; // what does this do? Instantiate the class CPlayer? // what's a forward...
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: Steve | last post by:
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...
1
by: Gustavo L. Fabro | last post by:
Greetings! Going directly to the point: myclass.h: //-------------------------------------- #pragma managed //Forward declaration
3
by: Eckart Haug | last post by:
I'm working with C# objects from managed C++ using the gcroot template. There'a a C++ header containing the definition of a C++ class: #using <mscorlib.dll> #include <vcclr.h> #using...
4
by: Jerome | last post by:
Hi all, I'm trying to use forward declaration with value class but I don't succeed in compiling my (quite simple) sample code. This is my code I'm trying to compile (Visual Studio 2003) ...
0
by: Eckart Haug | last post by:
Thanx for the quick reply. Your suggestion would mean that I'd have to add a C# reference to any C++ module that includes the C++ header. There's lots of them and I'd (for the moment) like to have...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
1
by: tobias_ebsen | last post by:
hi !! i have i function pointer that i declared in unmanaged code: void (*func_ptr)(); and i have a managed class where i need to assign a pointer to this function pointer and then call it....
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.