473,513 Members | 11,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

No appropriate default constructor available

Hello,

I'm trying to implement "Null-Field" feature (like Stream::Null) in MC++, but I am not able to initialize static member properly due to compiler error C2512 (no appropriate default constructor available):

public __gc class ObjectCollection : public CollectionBase
{
public:
ObjectCollection() { }

// CollectionBase Methods...

private:
__gc class NullObjectCollection; // Forward declaration

public:
static ObjectCollection *Null = new NullObjectCollection(); // <- Error C2512
};

__gc class ObjectCollection::NullObjectCollection : public ObjectCollection
{
public:
NullObjectCollection() { }
};

I've also tried to replace

static ObjectCollection *Null = new NullObjectCollection();

with

static ObjectCollection *Null;

static ObjectCollection() // Static Constructor
{
Null = new NullObjectCollection(); // <- C2512 Too
}

but with the same error... Any ideas? Is is only possible in C#?
Nov 17 '05 #1
3 2681

"Stanislav Simicek" <Stanislav Si*****@discussions.microsoft.com> wrote in
message news:7E**********************************@microsof t.com...
Hello,

I'm trying to implement "Null-Field" feature (like Stream::Null) in MC++, but I am not able to initialize static member properly due to compiler
error C2512 (no appropriate default constructor available):
public __gc class ObjectCollection : public CollectionBase
{
public:
ObjectCollection() { }

// CollectionBase Methods...

private:
__gc class NullObjectCollection; // Forward declaration

public:
static ObjectCollection *Null = new NullObjectCollection(); // <- Error C2512 };

__gc class ObjectCollection::NullObjectCollection : public ObjectCollection {
public:
NullObjectCollection() { }
};

I've also tried to replace

static ObjectCollection *Null = new NullObjectCollection();

with

static ObjectCollection *Null;

static ObjectCollection() // Static Constructor
{
Null = new NullObjectCollection(); // <- C2512 Too
}

but with the same error... Any ideas? Is is only possible in C#?


It's not enough to have type forward declaration to create its instance.
Type definition should be available.
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: www.nesterovsky-bros.com
Nov 17 '05 #2

"Stanislav Simicek" <St**************@discussions.microsoft.com> wrote in
message news:58**********************************@microsof t.com...
It's not enough to have type forward declaration to create its instance.
Type definition should be available.


The problem is where to define NullObjectCollection, because

public __gc class ObjectCollection ...
{
...
private:
__gc class NullObjectCollection : public ObjectCollection
{
// ...
}
}

does not compile - error C2504 "ObjectCollection: base class undefined".


Try the following:

public __gc class ObjectCollection: public CollectionBase
{
private:
__gc class NullObjectCollection;

static ObjectCollection *Null;

static ObjectCollection()
{
Null = CreateNullCollection();
}

static ObjectCollection * CreateNullCollection();
};

__gc class ObjectCollection::NullObjectCollection : public ObjectCollection
{
};

ObjectCollection * ObjectCollection::CreateNullCollection()
{
return new NullObjectCollection;
}
--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: www.nesterovsky-bros.com
Nov 17 '05 #3
Thank you very much, that solves the problem.
Nov 17 '05 #4

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

Similar topics

4
1392
by: news.microsoft.com | last post by:
BUG: struct default constructor is not displayed on intellisense yet it is available, BUG Make a struct type with a parameterized constructor. Try to construct the type in the IDE and...
4
2313
by: Duy Lam | last post by:
The compiler is complaining about "no appropriate default constructor available" when I reference a subclass. The basic setup is that i have a class Test and a subclass called TestKid. I want to...
17
2486
by: highli | last post by:
When a non-default constructor provided in a class, the default constructor is not available anymore. In what cases shall a default constructor be defined explicitly? Specifically, in the...
4
3774
by: stephane | last post by:
I can't make this work it says I dont have a default constructor available. Can someone tell me what's wrong with this please? #include <iostream> using namespace std; #include "points.h" ...
5
21575
by: Ook | last post by:
Here is my code, can some kind soul tell me what I'm doing wrong, or why I get this compile error, and maybe what to do to prevent it? I think I must be missing some fundamental concept here, or...
0
1943
by: WithPit | last post by:
I have some problems with the instantiating new objects. For example I have the following code //Headerfile (Texture1D.h> #pragma once #using <mscorlib.dll> #include <osg/Texture1D> #include...
3
4128
by: denis_browne | last post by:
When writing the following code: class Base { Base(const Base &rhs) {} ~Base(); }; void f() { Base b;
74
15870
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
3
3728
by: Rahul | last post by:
Hi Everyone, I have the following code and the compiler complains that there isn't any default constructor available, class C { private: C() {
0
7373
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
7432
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...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.