'MyCClass' has no constructors

J

Jim Tester

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
 
V

Victor Bazarov

Jim said:
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
 
J

Jim Tester

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
 
V

Victor Bazarov

Jim said:
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
 
H

hibiki

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top