J
James
How do you pass a string into a function and set the contents of an internal
string field to be the contents of the string passed into the Set method?
My attempt at doing this below doesn't work and produces errors such as
"class 'User' has an illegal zero-sized array" and "'=' : cannot convert
from 'char[]' to char[]'".
/* User.h */
class User
{
public:
void SetUserID(int u);
void SetName(char n[]);
private:
int user_id;
char name[];
};
/* END CLASS DEFINITION User */
#endif /* __USER__ */
/* User.cpp */
#include "User.h"
void User::SetUserID(int u)
{
user_id = u;
}
void User::SetName(char n[])
{
name = n;
}
P.S. How do you re-initialise an object e.g. in Java it's "new
ObjectName()", what's the C++ syntax?
string field to be the contents of the string passed into the Set method?
My attempt at doing this below doesn't work and produces errors such as
"class 'User' has an illegal zero-sized array" and "'=' : cannot convert
from 'char[]' to char[]'".
/* User.h */
class User
{
public:
void SetUserID(int u);
void SetName(char n[]);
private:
int user_id;
char name[];
};
/* END CLASS DEFINITION User */
#endif /* __USER__ */
/* User.cpp */
#include "User.h"
void User::SetUserID(int u)
{
user_id = u;
}
void User::SetName(char n[])
{
name = n;
}
P.S. How do you re-initialise an object e.g. in Java it's "new
ObjectName()", what's the C++ syntax?