Anything about this seem wrong? I keep getting errors about the character array.
class g_Vars
{
public:
char strAppName[8];
// Constructor
void g_vars( void );
};
void g_Vars::g_vars( )
{
strAppName = "testing";
}
Anything about this seem wrong? I keep getting errors about the character array.
class g_Vars
{
public:
char strAppName[8];
// Constructor
void g_vars( void );
};
void g_Vars::g_vars( )
{
strAppName = "testing";
}
Last edited by YingPar; 06-04-2003 at 10:22 PM.
Try strcpy(strAppName, "testing") from <cstring>.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
It's the same reason why you can't do this:
I think the explanation goes like this: the declaration creates space in memory for the array and text points to that location. However, it is a constant pointer. When you say:Code:int main() { char text[5]; text="hell"; return 0; }
text="hell";
what happens is "hell' is assigned a location in memory, and then that address is assigned to text. But text is a const pointer, so you get an error. Array names are pointers, but they are const pointers and you cannot modify their addresses.
Whatever the case, the problem is still continuing.
When I declare a value for the array outright (ie. strAppName = "..."; ), I get the following error:
When using the cstring function (ie. strAppName = strcpy( Global.strAppName, "ADVENTURE! by Sean Gilleran" ); ), I get the following error:error C2106: '=' : left operand must be l-value
error C2440: '=' : cannot convert from 'char *' to 'char [28]'
I just realized my mistake (strcopy doesn't return anything), and fixed it, and that seems to get the program working again.
But I'm still confused about that first error. It seems to me I've set the value of a char array before without a hassle.
"When I declare a value for the array outright (ie. strAppName = "..."; ),"
You can't do that in a class. You can only declare a data member. Initialization takes place in the contructor. Since when have you ever done this:
??Code:class my_class { public: int number = 10; };
You can declare a char array and intialize it at the same time:
char text[] = "hello";
but that isn't what is happening with an object of your class.
[Deleted, sorry, my mistake]