小编brf*_*rfh的帖子

理解的问题浮于c ..为什么会陷入无限循环?

我试图更新我的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)

为什么这样工作?

c floating-point loops

2
推荐指数
1
解决办法
82
查看次数

如何重载虚拟操作员

我有一个简单的继承结构:

  • 基本<-派生1
  • 基数<-衍生2

我想重载<<和>>运算符以输入和打印对象Derived1Derived2类中的数据,作为对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班级中,并在Derived1Derived2班级中覆盖它们?

我想做这样的事情:

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)

c++ virtual operator-overloading

2
推荐指数
1
解决办法
48
查看次数

标签 统计

c ×1

c++ ×1

floating-point ×1

loops ×1

operator-overloading ×1

virtual ×1