Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 指向静态的指针_C++_Arrays_String_Pointers - Fatal编程技术网

C++ 指向静态的指针

C++ 指向静态的指针,c++,arrays,string,pointers,C++,Arrays,String,Pointers,类Student有一个静态成员Year,它是指向应指向动态分配数组的std::string的指针 class Student { private: string name; int year; string semester; int AmtClass; static string *Year[4]; //Skipping the public members }; string *Student::Year[4] = { "Freshman"

Student
有一个静态成员
Year
,它是指向应指向动态分配数组的
std::string
的指针

class Student
{
private:
    string name;
    int year;
    string semester;
    int AmtClass;
    static string *Year[4];

    //Skipping the public members
};

string *Student::Year[4] = { "Freshman", "Sophomore", "Junior", "senior" };
尝试初始化
年份时出现问题

ERROR: Cannot convert 'const char*' to 'std::string*' in initialization
为什么我会出错

struct A
{
    static std::string *cohort;
};

std::string * A::cohort = new std::string[4];
不清楚为什么要动态分配阵列。你可以用
std::array
std::dynarray

当你更新你的帖子时,你应该

std::string * Student::Year = new std::string[4] { "Freshman", "Sophomore", "Junior", "senior" };


你真的需要弄清楚你在问什么。就目前情况而言,这并没有太大意义。您不理解错误消息的哪一部分?
struct Student
{
    static std::string Year[];
};


std::string Student::Year[4] = { "Freshman", "Sophomore", "Junior", "senior" };