【发布时间】:2013-09-17 17:06:33
【问题描述】:
我和一些朋友开始了一个游戏项目,我们试图找出为什么我们的课程没有显示任何输出。我们已包含 SDL 2.0(只是让您知道,以防万一)
问题是我们有一个继承和填充的类......
class Tile {
private:
int textureId;
public:
Tile();
Tile(int texId);
~Tile();
void Print_Data();
}
class Tile_Gun : public Tile {
private:
int damage;
public:
Tile_Gun();
Tile_Gun(int texId, int dmg);
~Tile_Gun();
void Print_Data();
}
这是基本设置。我想为两者运行 Print_Data() 。 我在 main() 中创建了一个对象,并设置了断点来控制数据,这些数据似乎都停止并填充了预期的区域。但是当它启动 Print_Data() 函数时,它会在断点中的 couts 和 cins 处停止(它会运行它),但不会向控制台添加任何内容。
发生了什么事,如果您需要更多信息,请告诉我......(我想我会尽量简短)
我如何称呼班级:
int texId = 0, dmg = 5;
Tile_Gun testgun = Tile_Gun(texId, dmg);
//The 0 passed to the parent constructor with Tile::Tile(texId)
testgun.Print_Data();
编辑:
void Tile::Print_Data() {
int dummy;
cout << "My texId is: " << textureId;
cin >> dummy;
}
void Tile_Gun::Print_Data() {
int dummy;
cout << "My damage is: " << damage;
cin >> dummy;
}
【问题讨论】:
-
对我来说,
Tile_Gun testgun(texId, dmg); std::cout << testgun;似乎更明智。 -
以上代码中的cins和couts在哪里?
-
我在底部添加了 cins 和 couts =)
-
添加新行:
cout << "stuff" << endl;默认情况下,控制台很可能是行缓冲的。 -
在我调用 Print_Data() 之前的 main() 中?编辑:无论在哪里,它都不会出现!
标签: c++ inheritance iostream