变量未在此范围中声明 [英] variable not declared in this scope
问题描述
我正在为类做一个程序,并且由于某种原因,它在类定义中声明时给我这个错误。
I'm making a program for class, and for some reason it is giving me this error when it is declared in the class definition.
错误:在函数
'void setMessageBuffer(std :: string)'
错误:'message' code>未在此范围内声明。
error: in function
'void setMessageBuffer(std::string)'
error:'message'
was not declared in this scope.
class apple
{
private:
string message, message2;
public:
void setMessageBuffer(string);
};
void apple::setMessageBuffer(string messagebuff)
{
message = messagebuff;
}
我做了其他部分的程序,但由于某种原因,这部分似乎不想编译。
I've done other parts of the program like that and they work fine, but for some reason this part doesn't seem to want to compile.
推荐答案
您忘了把 apple ::
前面的方法名。您的错误讯息告诉我这个!
You forgot to put apple::
in front of the method name. Your error message tells me this!
error: in function 'void setMessageBuffer(std::string)'
error: 'message' was not declared in this scope.
与对比:
template.cpp: In member function ‘void apple::setMessageBuffer(std::string)’:
template.cpp:14:7: error: ‘another variable’ was not declared in this scope
(抱歉如果我错了,也许这只是我的编译器的行为,g ++ -4.6)
(Apologies if I'm wrong here, maybe it's just how my compiler is behaving, g++-4.6)
这篇关于变量未在此范围中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!