[1] http://bytes.com/topic/c/answers/624119-how-do-you-declare-use-static-constant-array-inside-class
[2] http://www.cplusplus.com/forum/beginner/2052/
HOW DO WE DECLARE AND INITIALIZE CONSTANT CHAR ARRAY? [1]
-----------------------------------------------------------
class Test
{
public:
static const int arr[]= {1,2,3}; // LINE 11
}
You can declare it here, but you can't initialize it here.
Initialize it in a separate definition.
Otherwise, you will get compiling error
"a brace-enclosed initializer is not allowed here before '{' token"
Header file:
class Test
{
public:
static const int arr[];
};
Implementation file in *.cpp:
const int Test::arr[3] = {1,2,3};
iostream linker error is solved by using g++ instead of gcc in makefile.
-----------------------------------------------------------------
Mistake to avoid when using 'inline'
-------------------------------------------------------------
1.Don't put inline in front of class constructor/destructor
2.Don't put inline in front of functions within 'namespace'.
linker error when using static variables in class [2]
--------------------------------------------------------
Tuesday, September 28, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment