473,387 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Initializing a static const member array of a class type

Is there a way to initialize an member array of user defined objects that is
declared static const?

For example:

const vec3f I(1,0,0);
const vec3f j(0,1,0);

class corner_functor
{
public:
corner_functor();

~corner_functor();
static const Vec3f dir[5] = {-I, J, I, -J, -I};//This doesn't work
private:
int index;

};
I also tried some variations of this:

const SbVec3f* corner_functor::dir =
{
-I, J, I, -J, -I
};
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #1
1 2524
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
Is there a way to initialize an member array of user defined objects that is declared static const?

For example:

const vec3f I(1,0,0);
const vec3f j(0,1,0);

class corner_functor
{
public:
corner_functor();

~corner_functor();
static const Vec3f dir[5] = {-I, J, I, -J, -I};//This doesn't work
private:
int index;

};


Only const int, long, short, char, bool, and integral constants in general
can be initialized in the class. Try,

class corner_functor
{
...
static const Vec3f dir[5];
};
const Vec3f corner_functor::dir[5] = {-I, J, I, -J, -I};

The above line should occur in the cpp file. You can also define I and J in
the same cpp file.
Note that the following is undefined in ANSI C++

// header.h
extern const Vec3f I;
extern const Vec3f J;

// functor.h
defines class corner_functor;

// functor.cpp
#include "header.h"
const Vec3f corner_functor::dir[5] = {-I, J, I, -J, -I};


Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rahul Joshi | last post by:
Hi, I want to create a static array whose size is also a const member of the class. Something like: // A.h class A { private: static int size = 0; static int array;
2
by: Neno | last post by:
Hi, I have a linkage error that has something to do with the use of a static member array and I can't understand how to solve the problem. Can someone help me please? In detail: A class Month...
2
by: Drew McCormack | last post by:
I am getting an error in g++ 4.0.0 that I did not get in g++ 3.4. I have a header with the following const variables with namespace scope: namespace Periphery { extern const double...
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
3
by: Mark Dunmill | last post by:
I can't create a Constant/Read-only array field in managed C++ classes - doesn't allow the keyword const pointer to const object on array fields in managed C++ classes. e.g. Want to define a...
2
by: utab | last post by:
Dear all, I am confused at some point on the initialization of static map member of a class. The class I have designed id something like this. class Class_name{ public: private:
4
by: jayharris | last post by:
I'm having a ton of trouble initializing a multi-dimensional array inside a constructor, largely because I don't know the size of the array until runtime. I have a class that looks like this: ...
6
by: alacrite | last post by:
If I have this situation class X { Z z; Y y; }; Class X has two objects of type Z and Y. How do I initialize z and y with non default constructors?
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.