As As
As As

Reputation: 2107

Operator << with virtual classes

i have a problem. I have a class logic, with a string and an object. I want that when i write cout<<a in the logic class, this operator changes my string. So i did this:

logic.h

class logic
{
private:
int str;
A a;
public:
...
};

logic.cpp

...
...
cout<<*a;
...

ostream& operator<<(ostream& os, const A& A)
{
    int=a.num;
    return os;
}

z.h

class Z
{
public:
virtual Z* aa();
...
};

a.h

class A: public Z
{
private:
int num;
public:
virtual Z* aa();
...
};

And i got these errors:

expected class-name before '{' token (on class A:public Z { ) ISO C++ forbids declaration of 'Z' with no type, 'Z' declared as a 'virtual' field, expected ';' before '*' token (on every virtual function in A)

Can you help me?

Upvotes: 0

Views: 127

Answers (1)

user1203803
user1203803

Reputation:

You need a semicolon after the class definition:

class A: public Z
{
private:
  int num;
  public:
  virtual Z* aa();
  // ...
}; // <-- SEMICOLON!!1

Also, make sure that Z is defined before A is defined, by #includeing z.h in a.h.

Upvotes: 3

Related Questions