C ++ stl list of two cross-reference structures

I have code like this with 2 structures:

#include <list>

using namespace std;

struct Connection;
struct User;    

typedef list<Connection> Connections;
typedef list<User> Users;

struct User {
    Connections::iterator connection;
};

struct Connection {
    Users::iterator user;
};

But when I try to compile it, the compiler (C ++ Builder XE) returns me such an error - " Undefined structure" Connection ".

Can someone help me with my problem?

@ereOn, struct Connection; struct User; struct Connection {Users :: iterator user; }; typedef list Connections; List of users typedef;

struct User {
    Connections::iterator connection;
};

Undefined Structure 'User'

+3
source share
2 answers

You use an incomplete type as an argument to a type std::listthat calls undefined bevahior according to the C ++ standard.

§17.4.3.6 / 2 states:

, undefined :
 - (3.9) .

, .

struct Connection;
struct User;    

typedef list<Connection*> Connections; //modified line
typedef list<User*> Users;             //modified line

struct User {
    Connections::iterator connection;
};

struct Connection {
    Users::iterator user;
};

, , *, sizeof(Connection*), Connection .

+3

, : Connection , .

, typedef Connection.

+1

All Articles