-
gotta love my teacher
given:
Code:
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
ofstream Out("con"); //screen
//Out("rect.txt"); new disk file
//Oiyt("rect.txt",ios::app);
#include "rect.h"
#include "room.h"
void main(int argc, char *argv[]) //notice the void
{
//.....
}
and....
Code:
//room.cpp
#include "room.h"
Room::Room(void)
{
Out << "Room default constructor " << endl;
}
in Room::Room 'Out' is undeclared. why?
-
Thats a great teacher there misplaced...
-
so this isn't supposed to work?
-
You should write "extern std::ofstream Out" at the top of the room.cpp, or declare Out in room.h. (Global variables defined in one source file must have their type declared in another file. This declaration lets the compiler know Out's type and lets the linker fill in variable Out's address.)
-
Wha-what?!?!?!
C:\Dev-Cpp\project2\room.cpp In constructor `Room::Room()':
21 C:\Dev-Cpp\project2\room.cpp no match for 'operator<<' in 'Out << "Room default constructor "'
error C:\Dev-Cpp\project2\rect.h:11 candidates are: std::ostream& operator<<(std::ostream&, const Rectangle&)
offending line: Out << "Room default constructor " << endl;
i supose it's refering to this in rect.h:
friend ostream & operator <<(ostream &, const Rectangle &);
-
Maybe its a typo? Out -> cout ?
-
not a typo...in the next project we'll be writing to a file
-
I forgot to mention that you would need to have the following includes "#include <iostream>" and "#include <fstream>".