This question makes me feel a little stupid, but after spending hours working without success and combing through two books on C++ I still don't have the answer. That's partly because I'm slow, partly because C++ itself is brain-damaged, and partly because Microsoft has added so many extensions to the language that I'm simply stupified. And remember, this is .NET managed code(forms), not unmanaged MFC stuff.
Here it is, stripped down to the smallest and simplest file I can make and still demonstrate the problem.
//---------------------------------------------------------
namespace SomeNamespace
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
public __gc class YYY; //forward reference, adequate for declarations but not constructors
public __gc class XXX : public System::Windows::Forms::Form
{
public: XXX(void) //constructor
{
this->stupid = new YYY();
//error C2512: 'SomeNamespace::YYY' : no appropriate default constructor available
}
private: SomeNamespace::YYY *stupid;
};
public __gc class YYY : public System::Windows::Forms::IMessageFilter
{
public: YYY(void) //constructor
{
this->dumb = new XXX();
}
public: SomeNamespace::XXX *dumb;
};
}
//---------------------------------------------------------
What we have here are two objects in the same namespace referencing one another. What I can't figure out is why class XXX thinks there is no constructor for class YYY. This must have something to do with forward referencing, because class YYY has no problem finding the constructor for class XXX. I suspect that my "forward reference" line near the top of the file needs some additional info, but I have no idea what it's missing (if in fact that's the problem). What do I need to add to this file so the compiler knows about YYY's constructor?
Thanks for your help! ;-)
Here it is, stripped down to the smallest and simplest file I can make and still demonstrate the problem.
//---------------------------------------------------------
namespace SomeNamespace
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
public __gc class YYY; //forward reference, adequate for declarations but not constructors
public __gc class XXX : public System::Windows::Forms::Form
{
public: XXX(void) //constructor
{
this->stupid = new YYY();
//error C2512: 'SomeNamespace::YYY' : no appropriate default constructor available
}
private: SomeNamespace::YYY *stupid;
};
public __gc class YYY : public System::Windows::Forms::IMessageFilter
{
public: YYY(void) //constructor
{
this->dumb = new XXX();
}
public: SomeNamespace::XXX *dumb;
};
}
//---------------------------------------------------------
What we have here are two objects in the same namespace referencing one another. What I can't figure out is why class XXX thinks there is no constructor for class YYY. This must have something to do with forward referencing, because class YYY has no problem finding the constructor for class XXX. I suspect that my "forward reference" line near the top of the file needs some additional info, but I have no idea what it's missing (if in fact that's the problem). What do I need to add to this file so the compiler knows about YYY's constructor?
Thanks for your help! ;-)