|
-
April 6th, 2008, 02:20 PM
#1
problem with constructors and classes
I have a class like this:
Code:
#include "History.h"
class arena
{
public:
arena(some arguments)
: m_history(int num1, int num2) {};
private:
History m_hisory;
}
and history class is basically something like this:
Code:
//history.h
class history
{
public:
history(int num1, int num2){row=num1; col = num2;}
private:
int row, col;
}
the compiler says that i can't have 2 argument for m_history, in the arena constructors member initialization list. How can i overcome this problem?
-
April 6th, 2008, 02:53 PM
#2
Re: problem with constructors and classes
Please take the time to post the real code you're compiling. Don't hurredly type stuff in the message that looks like your code.
Code:
class history
{
public:
history(int num1, int num2){row=num1; col = num2;}
private:
int row, col;
};
class arena
{
public:
arena()
: m_history(int num1, int num2) {};
private:
History m_hisory;
};
Code:
Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.9 (Mar 27 2007 17:24:47) for ONLINE_EVALUATION_BETA1
Copyright 1988-2007 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"ComeauTest.c", line 16: error: identifier "History" is undefined
History m_hisory;
^
"ComeauTest.c", line 13: error: "m_history" is not a nonstatic data member or base
class of class "arena"
: m_history(int num1, int num2) {};
^
"ComeauTest.c", line 13: error: type name is not allowed
: m_history(int num1, int num2) {};
^
"ComeauTest.c", line 13: error: expected a ")"
: m_history(int num1, int num2) {};
^
4 errors detected in the compilation of "ComeauTest.c".
In strict mode, with -tused, Compile failed
This was after I had to add the semicolons to the end of the class definitions.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
Regards,
Paul McKenzie
-
April 6th, 2008, 03:13 PM
#3
Re: problem with constructors and classes
I will
sorry for the trouble you went through
-
April 6th, 2008, 04:40 PM
#4
Re: problem with constructors and classes
When you're initialising the object in the initialiser list, you don't repeat the types. Just supply actual arguments for the constructor.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
April 6th, 2008, 10:22 PM
#5
Re: problem with constructors and classes
That was my mistake wen i posted it. The problem like i said is that in the arena constructor, m_block() can't take more than one argument.
However, m_block's constructor does take 2 argumets....
-
April 6th, 2008, 11:41 PM
#6
Re: problem with constructors and classes
That was my mistake wen i posted it. The problem like i said is that in the arena constructor, m_block() can't take more than one argument.
However, m_block's constructor does take 2 argumets....
You probably have one or more typographical errors in your code. If you can make such errors when typing code to be posted (and you have made many such errors, by your own admission and obvious with casual inspection), you can make such errors when typing code to be compiled.
So, post your actual test program by copying and pasting the code from your IDE or text editor.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|