我已经在下面列出了我的代码。我收到了很多错误,说cout和endl没有在这个作用域中声明。我不知道我做错了什么,也不知道如何迫使类识别cout?我希望我正确地解释了我的问题。如果我注释掉方法(而不是构造器),它就能工作。我可能只是犯了一个新手的错误--请帮帮忙。
using namespace std;
class SignatureDemo{
public:
SignatureDemo (int val):m_Val(val){}
void demo(int n){
cout<<++m_Val<<"\tdemo(int)"<<endl;
}
void demo(int n)const{
cout<<m_Val<<"\tdemo(int) const"<<endl;
}
void demo(short s){
cout<<++m_Val<<"\tdemo(short)"<<endl;
}
void demo(float f){
cout<<++m_Val<<"\tdemo(float)"<<endl;
}
void demo(float f) const{
cout<<m_Val<<"\tdemo(float) const"<<endl;
}
void demo(double d){
cout<<++m_Val<<"\tdemo(double)"<<endl;
}
private:
int m_Val;
};
int main()
{
SignatureDemo sd(5);
return 0;
}发布于 2013-10-12 22:02:00
编译器首先需要知道在哪里可以找到std::cout。您只需要包含正确的头文件:
#include <iostream>我建议您不要使用using指令污染名称空间。相反,要么学习使用std::作为标准类/对象的前缀,要么使用特定的using指令:
using std::cout;
using std::endl;https://stackoverflow.com/questions/19331575
复制相似问题