【发布时间】:2015-06-29 10:32:42
【问题描述】:
在线documents 似乎建议将作为参数传递给同一类中的公共函数的类的私有成员变量需要声明为静态。不过,我得到一个编译错误:
class C{
private:
static std::string table1[50];
public:
bool try (){
helper(&table1);
return true;
}
bool helper (std::string * table){
return true;
}
但是我得到这个编译错误:
./c:72:31: error: cannot initialize a parameter of type 'std::string *' (aka
'basic_string<char, char_traits<char>, allocator<char> > *') with an rvalue of type
'std::string (*)[50]'
还有什么我错过的吗?
【问题讨论】:
-
也许你的意思是
helper(table1);? -
你能指出文档吗?我看不出为什么用作参数的私有成员变量需要是静态的。这将是一个严格的限制。
-
这就是我需要的,它最终工作了:try(){helper(table1)};助手(std::string * table);
标签: c++ function class static pass-by-reference