Inheritance problems

I have just begun implementing an inheritance program from my course. Unfortunately, the sample program that illustrates how it works also contains a previously written implementation of a 3d vector class with overloaded insertion/extraction operators. It's these operators that are showing errors. Since the code is kind of long, I'll try to summarize what my program looks like.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// inheritance.h 

#include "Vector3.h"
class A
{
   A(..., const Vector3& pos, ...);
   void printStats();   
};

class B : public A
{
   blabla
}




// Vector3.h    entire Vector3 header

class Vector3
{
public:
	Vector3();
	Vector3(float coords[3]);
	Vector3(float x, float y, float z);

	bool operator==(const Vector3& rhs);
	bool operator!=(const Vector3& rhs);
	Vector3 operator+(const Vector3& rhs);
	Vector3 operator-(const Vector3& rhs);
	Vector3 operator*(float scalar);
	float length();
	void normalize();
	float operator*(const Vector3& rhs);

	operator float*();   /*float* toFloatArray();*/

	void print();

	void input();

	float mX;
	float mY;
	float mZ;
};

Vector3 operator*(float scalar, Vector3& v); // so we can use 10 * v as well
istream& operator>>(istream& is, Vector3& v);
ostream& operator<<(ostream& os, const Vector3& v);



// main.cpp

#include "Vector3.h"
#include "inheritance.h"

int main()
{
   B something(..., Vector3(5.0f, 6.0f, -3.0f), ...);
   something.printStats();
}


All the errors stem from these two lines:
1
2
istream& operator>>(istream& is, Vector3& v);
ostream& operator<<(ostream& os, const Vector3& v);


If I comment out these lines, the program runs, but without the overloaded operators, the function printStats() outputs gibberish values, that look like addresses. For example: 00FBF88C instead of 5, 6, -3.
I tried making the overloads friends in both A and B. Still the same.

Can you even combine friend and inheritance? Or is this a completely different problem?
What do those errors say?

How can you possibly compile a code like:
1
2
Vector3 v;
std::cout << v;

... if you don't have that operator<< ?

Addresses hint about printing a pointer:
1
2
Vector3 * v;
std::cout << v;

That uses operator<< that takes void*.

So now I guess that the error message might say: "I cannot decide whether to convert Vector3* to void* or to const Vector3&"
But that is just a wild guess.
Error 1 error C2143: syntax error : missing ';' before '&'
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 3 error C2065: 'is' : undeclared identifier
Error 4 error C2065: 'v' : undeclared identifier
Error 5 error C2275: 'Vector3' : illegal use of this type as an expression
Error 6 error C1903: unable to recover from previous error(s); stopping compilation

They keep on repeating after that, all pointing to the two lines I mentioned.

<< does have the implementation written, and it works if I print a vector by itself. The problem is passing it off to printStats().







How is the identifier "istream" declared?
Instead of ostream, try writing std::ostream, and similarly for other names in the std namespace.
OMG ARE YOU SERIOUS?!
I forgot to include iostream in inheritance.h file.....Pff, it seems I'm beginning to overlook the simple things lately.
Sorry for wasting your time guys, and thanks LB for saving me the rest of the day lol.
Topic archived. No new replies allowed.