I'm currently nearing the end of a college C++ course and have hit a very frustrating wall while working on my current lab. After having typed up the majority of the code I need I hit the compile button and as always there were a lot of errors. Naturally, I started tracking down all the syntax errors in hops that it would compile and I would then know if the things I have done so far are correct.
The problem came very quickly when I noticed that the errors being thrown were from one of the three files given by the instructor. The specific one where the errors are being thrown is a file I know works because it was part of his example programs from earlier in the semester and it compiles and runs fine there. But here in my project, the compiler is throwing about 30 errors on the same line.
All the errors are being thrown on the operator<<() function line of this header file.
//Cow3.h -- example showing deep copy constructor
#ifndef _COW3_H_
#define _COW3_H_
#include <iostream>
class Cow
{
private:
char * name;
double weight;
public:
Cow();
Cow(constchar * n, double w = 0.0);
//new copy constructor to do deep copy
Cow(const Cow & c);
~Cow();
void set(constchar * n, double w = 0.0);
Cow & operator=(const Cow & c);
friend ostream & operator<<(ostream & os, const Cow & c);
};
#endif
The specific errors it is throwing are these, repeatedly for each .cpp file in the project.
1 2 3 4 5 6
1>c:\users\nicholas\documents\school\csci222\lab4\lab4\cow3.h(20): error C2143: syntax error : missing ';' before '&'
1>c:\users\nicholas\documents\school\csci222\lab4\lab4\cow3.h(20): error C2433: 'ostream' : 'friend' not permitted on data declarations
1>c:\users\nicholas\documents\school\csci222\lab4\lab4\cow3.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\nicholas\documents\school\csci222\lab4\lab4\cow3.h(20): error C2061: syntax error : identifier 'ostream'
1>c:\users\nicholas\documents\school\csci222\lab4\lab4\cow3.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\nicholas\documents\school\csci222\lab4\lab4\cow3.h(20): error C2805: binary 'operator <<' has too few parameters
I was wondering if anyone here might be able to point me in the right direction.
There is actually a usingnamespace std; in the .cpp file before the #include "Cow3.h" that I think should have effected that. I re-wrote the problem function and the prototype exactly as they were and it worked, but I'm going to change the lines to std::ostream just to be sure anyways.