Multiple references to abstract class in the same line

51 Views Asked by At

I have the following code:

class Agent {
public:
    Agent();
    int foo=5;
protected:
    virtual int Calculate() = 0;
};

class Game {
public:
    Game();
    Agent& agent0, agent1;
};

This code fails to compile with the error:

error: cannot declare field ‘Game::agent1’ to be of abstract type ‘Agent’

However, when you split the line Agent& agent0, agent1; into two lines:

Agent& agent0;
Agent& agent1;

it compiles fine. Why is this happening? I thought there should be no difference between the two.

0

There are 0 best solutions below