如何创建指向私有静态类成员的以下指针数组?
class Auth {
private:
static char *attribs[3];
attribs[0]="uid";
attribs[1]="cn";
attribs[2]=NULL;
}
我不知道如何以及在哪里(什么在.h和什么在.cpp中?)来放置这些线......
答案 0 :(得分:1)
假设您有权访问C ++ 11,您应该考虑std::string
和std::vector
而不是C风格的数组和C风格的字符串
#include <vector>
#include <string>
class Auth {
private:
static std::vector<std::string> attribs;
};
std::vector<std::string> Auth:: attribs = {"uid", "cn"};
答案 1 :(得分:0)
在auth.h
:
class Auth {
private:
static char *attribs[3];
};
在auth.cpp
:
char* Auth::attribs[3] = { "uid", "cn", NULL };