By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,857 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

'MyCClass' has no constructors

P: n/a
I have the following class:

In MyIClass

class MyInterfaceClass
{
public:
explicit MyInterfaceClass( char const * const pName, bool init );
virtual ~MyInterfaceClass( void );

// Some pure virtual functions
}

I then create the following class:

class MyCClass :
public MyInterfaceClass
{
public:
explicit MyCClass( char const * const pName, bool init );
virtual ~MyCClass( void );

// The overloaded virtual functions from MyInterfaceClass
}

Both of the constructors and destructors are defined in their respective
..cpp
file.

Then somewhere else I do the following:

MyCClass cclass = new MyCClass("Name", true);

However I get the following compilation error:

error 2514: 'MyCClass' has no constructors

What could be a reason I get this error?

Thanks,
Jimmy
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jim Tester wrote:
I have the following class:

In MyIClass

class MyInterfaceClass
{
public:
explicit MyInterfaceClass( char const * const pName, bool init );
virtual ~MyInterfaceClass( void );

// Some pure virtual functions
}

I then create the following class:

class MyCClass :
public MyInterfaceClass
{
public:
explicit MyCClass( char const * const pName, bool init );
virtual ~MyCClass( void );

// The overloaded virtual functions from MyInterfaceClass
}

Both of the constructors and destructors are defined in their respective
.cpp
file.

Then somewhere else I do the following:

MyCClass cclass = new MyCClass("Name", true);
Should be

MyCClass * class = new MyCClass("Name", true);

(note the asterisk)

However I get the following compilation error:

error 2514: 'MyCClass' has no constructors

What could be a reason I get this error?


See above. If that's not the actual mistake you made in the code but
a typo you made when typing the code into the posting (instead of copy-
and-pasting it, like normal people), then it is possible that you have
your MyCClass forward-declared and not defined at the time when you try
to construct it. Don't forget to include the proper header.

V
Jul 23 '05 #2

P: n/a
Thanks, yes that was a typo. But I did as you've noted add the header to
the file and it works. Thanks.

Another question in regards to headers now. I have a main file called
"includes.h" in which I include all the headers in my project there as such:

include.h
-------------------------------
my.h
another.h
more.h
evenmore.h
-------------------------------

And then I include includes.h to all the other files. Although I thought
this was the best way of going about this, it's apparently not.

So then should I just include the correct header files in any file that
needs them instead of trying to have a "blanket" header file that includes
all the other files?

Thanks
Jimmy

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:LN*******************@newsread1.mlpsca01.us.t o.verio.net...
Jim Tester wrote:
I have the following class:

In MyIClass

class MyInterfaceClass
{
public:
explicit MyInterfaceClass( char const * const pName, bool init );
virtual ~MyInterfaceClass( void );

// Some pure virtual functions
}

I then create the following class:

class MyCClass :
public MyInterfaceClass
{
public:
explicit MyCClass( char const * const pName, bool init );
virtual ~MyCClass( void );

// The overloaded virtual functions from MyInterfaceClass
}

Both of the constructors and destructors are defined in their respective
.cpp
file.

Then somewhere else I do the following:

MyCClass cclass = new MyCClass("Name", true);


Should be

MyCClass * class = new MyCClass("Name", true);

(note the asterisk)

However I get the following compilation error:

error 2514: 'MyCClass' has no constructors

What could be a reason I get this error?


See above. If that's not the actual mistake you made in the code but
a typo you made when typing the code into the posting (instead of copy-
and-pasting it, like normal people), then it is possible that you have
your MyCClass forward-declared and not defined at the time when you try
to construct it. Don't forget to include the proper header.

V

Jul 23 '05 #3

P: n/a
Jim Tester wrote:
Thanks, yes that was a typo. But I did as you've noted add the header to
the file and it works. Thanks.

Another question in regards to headers now. I have a main file called
"includes.h" in which I include all the headers in my project there as such:

include.h
-------------------------------
my.h
another.h
more.h
evenmore.h
-------------------------------

And then I include includes.h to all the other files. Although I thought
this was the best way of going about this, it's apparently not.

So then should I just include the correct header files in any file that
needs them instead of trying to have a "blanket" header file that includes
all the other files?


Please don't top-post, or use common sense in quoting (or trimming of what
you quote). Thanks.

Regarding headers, your approach (with bundling them up in one header) is
valid and used by some organizations especially when headers do not change
much from build to build, which allows them to be precompiled, etc.
However, for the maintainability and readability of any single translation
unit I do prefer to have all headers included in it explicitly, and only
the ones that contain the declarations/definitions of symbols used in that
translation unit. IOW, if I use 'printf', I know I need <cstdio>, and if
I use 'pair' I need <utility> no matter if I have already included <map>
(which might include <utility> in my implementation, for example).

The rule of thumb many folks here subscribe to is simple: in any file you
write which contains externally defined/declared symbols, you need to add
the #include directive for the header that defines/declares that symbol.
It doesn't matter if your file is a C++ source or another header. So, you
may end up including some headers twice in some translation units, or more
times, but that should present no particular problem if the header has so
called "multiple inclusion guards".

HTH

V
Jul 23 '05 #4

P: n/a
Jim Tester a écrit :
I have the following class:

In MyIClass

class MyInterfaceClass
{
public:
explicit MyInterfaceClass( char const * const pName, bool init );
virtual ~MyInterfaceClass( void );

// Some pure virtual functions
}

I then create the following class:

class MyCClass :
public MyInterfaceClass
{
public:
explicit MyCClass( char const * const pName, bool init );
virtual ~MyCClass( void );

// The overloaded virtual functions from MyInterfaceClass
}

Both of the constructors and destructors are defined in their respective
.cpp
file.

Then somewhere else I do the following:

MyCClass cclass = new MyCClass("Name", true);

However I get the following compilation error:

error 2514: 'MyCClass' has no constructors

What could be a reason I get this error?

Thanks,
Jimmy

What's thid char const * const pName ?
Isn't it const char* pName instead ?

--
Salutations,

Joachim Naulet

06 14 90 06 21
http://jnaulet.no-ip.com
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.