刚进入C++,我有一个简单的问题.
编译完成后
g++ *.cpp -o output
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
error: 'ostream' in 'class Dollar' does not name a type
Run Code Online (Sandbox Code Playgroud)
这些是我的三个文件:
main.cpp中
#include <iostream>
#include "Currency.h"
#include "Dollar.h"
using namespace std;
int main(void) {
Currency *cp = new Dollar;
// I want this to print "printed in Dollar in overloaded << operator"
cout << cp;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Dollar.cpp
#include <iostream>
#include "Dollar.h"
using namespace std;
void Dollar::show() {
cout << "printed in Dollar";
}
ostream & operator << (ostream &out, const Dollar …Run Code Online (Sandbox Code Playgroud)