Board index » cppbuilder » static const AnsiString

static const AnsiString


2005-08-10 05:50:54 PM
cppbuilder35
Ca, someone tell me why this line is not allowed in a class
class TPanier : public TForm
public:
static const AnsiString="bla bla bla";//ERROR HERE
(...)
};
Thanks.
Sam
 
 

Re:static const AnsiString

sam wrote:
Quote
Ca, someone tell me why this line is not allowed in a class
class TPanier : public TForm
public:
static const AnsiString="bla bla bla";//ERROR HERE
(...)
};
Two reasons:
1. You haven't given the static member variable a name.
2. You can't initialize static const members in the class definition
(with the exception of integral const members).
You need:
class TPanier : public TForm
public:
static const AnsiString aString;
(...)
};
//in source file:
const AnsiString TPanier::aString = "blah blah blah";
Tom
 

Re:static const AnsiString

"sam" < XXXX@XXXXX.COM >writes:
Quote
Ca, someone tell me why this line is not allowed in a class
class TPanier : public TForm
public:
static const AnsiString="bla bla bla";//ERROR HERE
(...)
};
You have a few problems. First, you're not declaring a variable.
There is no name provided for your string.
Second, you are not allowed to initialize any variables in the class
declaration unless they have a static const INTEGRAL type.
Instead, you'd need to do this:
class TPanier : public TForm
public:
// declaration
static const AnsiString qqch;
};
// .cpp file
// definition
AnsiString TPanier::qqch("bla bla bla");
Static variables must be defined only once, so the definition goes in
a single .cpp file. (This is similar in concept to declaring a global
variable, except it is contained inside a class.)
--
Chris (TeamB);
 

{smallsort}