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

2 questions for help!

1. When defining only a copy constructor but no other constructors, the
default constructor will not be available any more in a class?

2.
class CEngine
{
....
public
// CEngine();//Without this, error happens
CEngine(int volume);
....
};
class CFord : public CCar
{
CEngine e;

public:
CFord(const CFord& f);
CFord& operator=(const CFord& f);
....
};

When adding CFord(const CFord& f); into CFord, the error happens:

error C2512: 'CEngine' : no appropriate default constructor available.

To solve the problem, add a default constructor by myself. Is there any
better solution?

How to force to use the CEngine(int volume) constructor?

Jul 22 '05 #1
1 959
Birt wrote:
1. When defining only a copy constructor but no other constructors, the
default constructor will not be available any more in a class?
That's not a question.
2.
class CEngine
{
...
public
// CEngine();//Without this, error happens
CEngine(int volume);
...
};
class CFord : public CCar
{
CEngine e;

public:
CFord(const CFord& f);
CFord& operator=(const CFord& f);
...
};

When adding CFord(const CFord& f); into CFord, the error happens:

error C2512: 'CEngine' : no appropriate default constructor available.

To solve the problem, add a default constructor by myself. Is there any
better solution?
Well, there was a default constructor before (the implicitly declared
default constructor), and you were using it, so why not have a default
constructor now? Are you sure you no longer need one?
How to force to use the CEngine(int volume) constructor?


Pass an integer argument when the CEngine object is created. Data
members are initialized before the body of the constructor is entered,
so there is a special syntax for passing arguments to data member
constructors:

int some_integer = 0;

CFord::CFord (const CFord & f)
: e (some_integer)
{
// constructor body
}

--
Regards,
Buster.
Jul 22 '05 #2

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

Similar topics

4
by: Skip Montanaro | last post by:
(moving over from webmaster mailbox) scott> I'm sorry for bothering you, but I've tried to post to the Python scott> Tutor Mail List, tried to get someone from Bay PIggies to scott> respond, but...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
1
by: jason | last post by:
Hello everyone, I have some general questions about the DataTable object, and how it works. Moderately new to C#, I have plenty of texts describing the language, but not so much to reference...
13
by: M.Siler | last post by:
Let me clarify from my last post. I am not using these 4 questions as the sole screening method. Currently in, the Tampa Bay area (Florida) there is an extreme shortage of C# developers. We have...
0
by: Jobs | last post by:
All answers to the below interview questions are at http://www.geocities.com/dotnetinterviews/ or you can download the complete answer zip file from...
24
by: tom c | last post by:
I have gotten great help in this forum. I am working by my self, developing with a new technology, and it would be extremely time consuming and frustrating without this forum. So who are the...
2
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate...
4
by: Viviana Vc | last post by:
Hi all, I've read the WindowsVistaUACDevReqs.doc documentation and I have done different small tests on Vista to understand the bahaviour and now I have a few questions. 1) If I create a...
8
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying...
16
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, I am using Visual C# window to dispaly a set of questions with their answers. The users should be able to move to the next question by clicking on next button. I am going to use only one panel...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.