Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to declare static members of class

Status
Not open for further replies.

Weber1

Programmer
Sep 9, 2000
20
US
I have a class which has temporary variables:

// Private temporary classes used by this class.
static C_coordinate3d* tempcoord3d1;
static C_vector3d* tempvector3d1;
static C_line_segment_3d* templineseg3d1;
static C_coordinate3d* tempcoord3d2;
static C_vector3d* tempvector3d2;
static C_line_segment_3d* templineseg3d2;

declared in the class in the header file. In the .cpp file, I have the statements:

// ----------------------------------
// Private temporary classes used by this class.
// Initial values not important as they are changed each time they are used;
// These variables not deleted since they are instantiated for the class, not
// per instance.
C_polygon_flat_surface::tempcoord3d1 = new C_coordinate3d(0, 0, 0);
C_polygon_flat_surface::tempvector3d1 = new C_vector3d(tempcoord3d);
C_polygon_flat_surface::templineseg3d1 = new C_line_segment_3d(tempcoord3d, tempcoord3d);
C_polygon_flat_surface::tempcoord3d2 = new C_coordinate3d(0, 0, 0);
C_polygon_flat_surface::tempvector3d2 = new C_vector3d(tempcoord3d);
C_polygon_flat_surface::templineseg3d2 = new C_line_segment_3d(tempcoord3d, tempcoord3d);
// ----------------------------------

to initialize these members (these are temporary variables that I want to use, but do not want to create every time I create the class.)
The compiler is saying:

c:\game development\math and logic utilities\geometric classes2.cpp(219) : error C2501: 'tempcoord3d1' : missing storage-class or type specifiers
c:\game development\math and logic utilities\geometric classes2.cpp(219) : error C2040: 'private: static class C_coordinate3d * C_polygon_flat_surface::tempcoord3d1' : 'int' differs in levels of indirection from 'class C_coordinate3d *'

etc...

Anyone know why this doesn't work?

 
in the CPP file, at the top you do

C_coordinate3d* C_polygon_flat_surface::tempcoord3d1;
C_vector3d* C_polygon_flat_surface::tempvector3d1;
C_line_segment_3d* C_polygon_flat_surface::templineseg3d1;
C_coordinate3d* C_polygon_flat_surface::tempcoord3d2;
C_vector3d* C_polygon_flat_surface::tempvector3d2;
C_line_segment_3d* C_polygon_flat_surface::templineseg3d2;

Matt

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top