[英]iostream not printing to terminal in second source class (c++)
When I try to do a cout in a constructor it will not print out. 当我尝试在构造函数中执行cout时,它不会打印出来。 I know cout works on my terminal because I can call it from the main(), but not from my CharacterStats.cpp class with a CharacterStats.hpp header.
我知道cout在我的终端上可以正常工作,因为我可以从main()调用它,但是不能从我的CharacterStats.cpp类(带有CharacterStats.hpp标头)调用它。
There is no terminal output like there should be. 没有应有的终端输出。 I am expecting
"---DATALESS UNIT CREATED---"
to appear in the output 我希望输出中出现
"---DATALESS UNIT CREATED---"
I use 我用
g++ -o a main.cpp CharacterStats.cpp CharacterStats.hpp
./a
to compile and execute and nothing print out 编译和执行,什么也没打印出来
#include "CharacterStats.hpp"
int main(void){
CharacterStats coreUser();
return 0;
}
#include "CharacterStats.hpp"
#include <iostream>
using namespace std;
CharacterStats::CharacterStats(char name, bool type, short strength, short armor, short resist, short speed, short luck){
cout << "---CORE DECLARED---" << endl;
this->name = name;
this->type = type;
this->strength = strength;
this->armor = armor;
this->resist = resist;
this->speed = speed;
this->luck = luck;
}
CharacterStats::CharacterStats(){
cout << "---DATALESS UNIT CREATED---" << endl;
}
#ifndef CHARACTER_STATS
#define CHARACTER_STATS
class CharacterStats{
private:
char name;
bool type;
short strength, armor, resist, speed, luck;
public:
CharacterStats(char, bool, short, short, short, short, short);
CharacterStats();
};
#endif /* CHARACTER_STATS */
It's because you aren't calling your constructor. 这是因为您没有调用构造函数。
CharacterStats coreUser();
declares a function taking no arguments and returning a CharacterStats
. 声明一个不带参数的函数 ,并返回
CharacterStats
。
What you want is 你想要的是
CharacterStats coreUser;
Easy mistake to make. 容易犯的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.