473,322 Members | 1,806 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,322 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 2439
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.