我试图更新我的C知识,并且遇到了float错误。
例如,此循环将是无限的:
#include <stdio.h>
int main(){
for (float i =18000000; i<18000002; i++){
printf("%f\n", i);
}
printf("win\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么这样工作?
我有一个简单的继承结构:
我想重载<<和>>运算符以输入和打印对象Derived1和Derived2类中的数据,作为对Base类的引用。
我可以声明某种虚函数吗?像这样 :
virtual std::ostream& operator<<(std::ostream& os, const Base& obj) = 0;
virtual std::istream& operator>>(std::istream& is, Base& obj) = 0;
Run Code Online (Sandbox Code Playgroud)
在我的Base班级中,并在Derived1和Derived2班级中覆盖它们?
我想做这样的事情:
std::vector<Base&> a;
... push reference to Derived1 and Derived2 objects ...
for (auto i = a.begin(); i != a.end(); ++i) std::cin >> (*i);
for (auto i = a.begin(); i != a.end(); ++i) std::cout << (*i);
Run Code Online (Sandbox Code Playgroud)