Help with misleading compiler errors

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//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(const char * n, double w = 0.0);
    //new copy constructor to do deep copy
    Cow(const Cow & c);
    ~Cow();
    void set(const char * 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.
You must have some unclosed '{' in the file that included Cow3.h or an other incorrenct statement termination, so everything following is badly parsed
ostream is in the std namespace.
So you need to write std::ostream

They were using an old compiler
There is actually a using namespace 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.
Topic archived. No new replies allowed.