|
-
April 10th, 2003, 04:21 AM
#1
Constructor using problems...
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:
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:
template < class T>
class COcVector {
public:
COcVector( int dim){} // standard constructor
COcVector( const COcVector< T> & v){} // copy constructor
~COcVector(){}
};
Any help greatly appreciated!
carnaz
-
April 10th, 2003, 04:51 AM
#2
You initialise the _origin member in the COcPMatrix constructor:
Code:
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).
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
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
|