Только что изучил C ++, и у меня быстрый вопрос.
После компиляции с
g++ *.cpp -o output
Я получаю такую ошибку:
error: 'ostream' in 'class Dollar' does not name a type
Это мои три файла:
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;
}
Dollar.cpp
#include <iostream>
#include "Dollar.h"
using namespace std;
void Dollar::show() {
cout << "printed in Dollar";
}
ostream & operator << (ostream &out, const Dollar &d) {
out << "printed in Dollar in overloaded << operator";
}
Dollar.h
#include "Currency.h"
#ifndef DOLLAR_H
#define DOLLAR_H
class Dollar: public Currency {
public:
void show();
};
ostream & operator << (ostream &out, const Dollar &d);
#endif
Спасибо за уделенное время, все помогает!
std::ostream
. - person juanchopanza   schedule 17.01.2018using namespace std;
. - person Ron   schedule 17.01.2018#include "Currency.h"
на после#define DOLLAR_H
- person user4581301   schedule 17.01.2018