473,394 Members | 1,774 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,394 software developers and data experts.

'MyCClass' has no constructors

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
4 1773
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
6
by: Stephen Martinelli | last post by:
thanks for the help...just one more question.... can a class have more then two parameterized constructors?..i would like to be able to instanciate the class with a different number of...
10
by: John | last post by:
Trying to find out what is essential / optional, I made an extremely simple Class and Module combination to add two numbers. (see below) It appears that an empty constructor is needed n order to...
3
by: John | last post by:
Before anything else, thanks Marina, Workgroups and Ralf, for your help so far. I am now able to better define the question! After adding more console printout lines to CSum, I tried all...
22
by: Peter Morris [Droopy eyes software] | last post by:
Look at these two classes public class Test { public readonly string Name; public Test(string name)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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...

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.