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?
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
Re: problem with constructors and classes
I will
sorry for the trouble you went through
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.
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....
Re: problem with constructors and classes
Quote:
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.