Forward declaration of objects with STL containers

Consider the following code fragment, where the first line serves only as a forward declaration

 class A;

followed by the definition of a new class

class B
{
 vector<A> Av;  //line 1
 map<int, A> Am;  //line 2
 pair<int, A> Ap; //line 3
};

line 1 and line 2 look fine with forward declarations (which may tell me that this type of pointer use uses this type of implementation) when line 3 does not seem to compile on VS2012.

My question is, is the behavior dictated by the standard or specific to the compiler that I use?

thank

+4
source share
3 answers

The relevant rules for standard library types are in [res.on.functions]:

, undefined : [...], (3.9) , .

:

vector<A> Av;

. std::vector , , - . [vector.overview]:

T vector, 17.6.3.5.1. T , .

std::list std::forward_list.

:

map<int, A> Am;

. std::map . , vector.

:

pair<int, A> Ap;

, pair - . A, .

+7

, .

, std:: pair , .

+2

[ ]

(++ 17), std::vector, std::list std::forward_list.

§23.3.11.1/3 [Vector.overview]:

T vector, [allocator.requirements.completeness]. T , - vector.

§23.3.9.1/4 forward_list [Forwardlist.overview]:

T forward_list, [allocator.requirements.completeness]. T , - forward_list.

§23.3.10.1/3 [List.overview]:

T list, [allocator.requirements.completeness]. T , - list.

+2

Source: https://habr.com/ru/post/1650929/


All Articles