W
wyndz0108
hello,
i have this program that prints out some text using ostream. i am
using g++ (GCC) 3.4.4; the original program compiles and run. refer to
first program below.
but when i modified it by moving the class to a header file, i
encountered an error. refer to second program below.
can somebody help?
// start of original program
#include <fstream>
#include <iostream>
using namespace std;
class outC {
public:
void display (ostream& out) { out << "testing 1, 2, 3" << endl;}
};
int main (int argc, char * argv) {
ofstream outfile;
outfile.open("out.tmp");
outC my;
my.display(outfile);
outfile.close();
return 0;
}
// end of original program
modified program with 2 files (main and header files)
//start of main file (modified program)
#include <fstream>
#include <iostream>
#include "out.h"
using namespace std;
int main (int argc, char * argv) {
ofstream outfile;
outfile.open("out.tmp");
outC my;
my.display(cout);
outfile.close();
return 0;
}
void outC::display (ostream& out) {
out << "testing 1, 2, 3" << endl;
}
// end of main file (modified program)
//start of header file (for the modified program)
#ifndef OUTH
#define OUTH
class outC {
public:
void display (ostream& out);
};
#endif
// end of header file (for the modified program)
i have this program that prints out some text using ostream. i am
using g++ (GCC) 3.4.4; the original program compiles and run. refer to
first program below.
but when i modified it by moving the class to a header file, i
encountered an error. refer to second program below.
can somebody help?
// start of original program
#include <fstream>
#include <iostream>
using namespace std;
class outC {
public:
void display (ostream& out) { out << "testing 1, 2, 3" << endl;}
};
int main (int argc, char * argv) {
ofstream outfile;
outfile.open("out.tmp");
outC my;
my.display(outfile);
outfile.close();
return 0;
}
// end of original program
modified program with 2 files (main and header files)
//start of main file (modified program)
#include <fstream>
#include <iostream>
#include "out.h"
using namespace std;
int main (int argc, char * argv) {
ofstream outfile;
outfile.open("out.tmp");
outC my;
my.display(cout);
outfile.close();
return 0;
}
void outC::display (ostream& out) {
out << "testing 1, 2, 3" << endl;
}
// end of main file (modified program)
//start of header file (for the modified program)
#ifndef OUTH
#define OUTH
class outC {
public:
void display (ostream& out);
};
#endif
// end of header file (for the modified program)