【发布时间】:2018-05-29 01:00:08
【问题描述】:
我想练习一些基本的 C++ 东西。我专注于继承只是为了试验它。一切都很顺利,直到我遇到一些奇怪的问题:'cout' 没有在这个范围内声明。我查看了一些主题,但大多数主题的提示都类似于附加库或编写“使用命名空间 std”,但这并不能解决我的问题。
#include <iostream>
class podst
{
public:
float a;
float b;
float dodaw();
podst(float c,float d) : a(c), b(d)
{
}
};
float podst::dodaw()
{
return (a+b);
}
class poch : public podst
{
poch() : podst(5,4)
{
cout << a << endl << b << dodaw() << endl;
}
};
using namespace std;
int main()
{
podst podst(1,2);
cout << podst.dodaw() << endl;
poch poch2;
return 0;
}
【问题讨论】:
-
使用
std::cout比使用using namespace std;要好得多。 stackoverflow.com/questions/1452721/…
标签: c++ inheritance scope cout