Skip to main content
gamedev.net
🔒 Locked

C++ ctor

Started by daniel_i_l Oct 6, 2006 at 9:51 AM 0 replies 600+ views
Original Post
daniel_i_l
daniel_i_l
Hi, i have the following structure:

struct Matrix3D
{
	//3 coloum vectors
	Vector3D C[3];

	//ctor - identity matrix
	Matrix3D():C[0].x(1), C[1].y(1), C[2].z(1){}
	//ctor - user defined
	Matrix3D(const Vector3D &c0, const Vector3D &c1, const Vector3D &c2)
		:C[0](c0),
		 C[1](c1),
		 C[2](c2)
	{}
...
...
};

but in both of the ctors i get the error: c:\documents and settings\daniel lowengrub\my documents\visual studio 2005\projects\physic\physic\physic\Matrix3D.h(16) : error C2059: syntax error : '[' What's the problem? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Simian Man
Simian Man
You can't construct the elements of an array in an initializer list like that. Just do it in the body of the constructor.
struct Matrix3D{	//3 coloum vectors	Vector3D C[3];	//ctor - identity matrix	Matrix3D()        {            C[0].x = 1;            C[1].y = 1;            C[2].z = 1;        }	//ctor - user defined	Matrix3D(const Vector3D &c0, const Vector3D &c1, const Vector3D &c2)        {            C[0] = Vector3D(c0);            C[1] = Vector3D(c1);            C[2] = Vector3D(c2);	}......};

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.