What is the problem in my code? It does not compile..
class FileNames
{
public:
static char* dir;
static char name[100];
static void Init3D()
{
FileNames::dir = "C://3D//";
FileNames::name = "abc";
}
};
You cannot assign to an array, so
FileNames::name = "abc"fails (char arr[4] = "abc"works, however, because this is a direct initialization, not assignment). Either use achar*here as well, or usestrcpyto copy data to the array or better astd::stringwhich avoids many of the downsides of raw strings.Most importantly you need to define your static members somewhere at global scope, outside a function:
char FileNames::name[100];. At this time initialization syntax using=would be possible even with the array, but the string to be assigned needs to have the same length as the array.