Click to See Complete Forum and Search --> : Constructor using problems...


carnaz
April 10th, 2003, 04:21 AM
Hi there,

I created a class COcVector, which contains standard constructor with one argument and copy constructor; There is not a constructor without any arguments, but when I tryied to use instances of that class in another class as a protected member variables, following error occured:

:confused: error C2059: Syntaxfehler : 'constant'
( syntax error)

Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'COcPMatrix<T>'
( see reference of compiled template)

I don't know hwether my translation is correct, but maybe the code will make it clear:

problem class::(

template < class T>
class COcPMatrix : public COcMatrix < T>{
public:
COcPMatrix() : COcMatrix < T> ( 3, 4){}
~COcPMatrix(){}

protected:

:( :( :( COcVector < T> _origin( 2);:( :( :( // this line causes an error mentioned above
};

used class::rolleyes:
template < class T>
class COcVector {

public:

COcVector( int dim){} // standard constructor
COcVector( const COcVector< T> & v){} // copy constructor
~COcVector(){}
};

Any help greatly appreciated!;)
carnaz

Graham
April 10th, 2003, 04:51 AM
You initialise the _origin member in the COcPMatrix constructor:

template < class T>
class COcPMatrix : public COcMatrix < T>
{
public:
COcPMatrix() : COcMatrix < T> ( 3, 4), _origin(2) {}
~COcPMatrix(){}

protected:

COcVector < T> _origin;
};

From a design point of view, I'd worry about making _origin protected. There is rarely a need for protected data members and their presence indicates either a design flaw or (very likely) a maintenance headache in the future.

By the way - don't use leading underscores in your identifiers: the standard reserves leading underscores in identifiers for use by compiler and standard library writers (it also reserves double underscores anywhere in the identifier, so don't use those either).