K
Kris
Hi All,
I just tried to do something that I thought would be quite simple in C++ and
discovered (I think) that it's not possible. I did a bunch of reading and
everything that I've seen seems to indicate that it's not possible but I
thought I'd throw it out to all you c++ gurus to see what you say.
Is there any way to initialize a character array in the initialization list
for the constructor a class? If this is not possible, can anyone explain why
c++ doesn't allow this? I've included sample code below to demonstrate what
I'm trying to do. Thanks in advance for any responses provided.
The Code
============
class myClass
{
public:
myClass(); // contructor
char myCharArray[100];
};
myClass::myClass() : myCharArray("")
{
//some other stuff here
}
The Compile Error
==============
error C2536: 'myClass::myClass::myCharArray' : cannot specify explicit
initializer for arrays
I just tried to do something that I thought would be quite simple in C++ and
discovered (I think) that it's not possible. I did a bunch of reading and
everything that I've seen seems to indicate that it's not possible but I
thought I'd throw it out to all you c++ gurus to see what you say.
Is there any way to initialize a character array in the initialization list
for the constructor a class? If this is not possible, can anyone explain why
c++ doesn't allow this? I've included sample code below to demonstrate what
I'm trying to do. Thanks in advance for any responses provided.
The Code
============
class myClass
{
public:
myClass(); // contructor
char myCharArray[100];
};
myClass::myClass() : myCharArray("")
{
//some other stuff here
}
The Compile Error
==============
error C2536: 'myClass::myClass::myCharArray' : cannot specify explicit
initializer for arrays