Forward declaration of use in C ++ 11

I am trying to use a type alias for an object in a different header without including a header file.

My simplified version of the code:

// A.h
    #include <vector>
    using Vector=std::vector<int>;

====================================================

//B.h
using Vector;//forward declaration but not working !(Vector has not beed declared)
int foo(Vector*);

====================================================
//B.cpp
#include "A.h"
void foo(Vector*){}

I don't want to write using Vector=std::vector<int>;again in B.h, because this definition should be the same as definition Vectorin A.h, and it may change in the future , and I can't include it because my code has a circular dependency .

Is a declaration of usingpossible in C ++ 11?

+4
source share
1 answer

This is not possible, however the following may be a workaround.

// Common.h
...
#include <vector>
using Vector=std::vector<int>;
...

Common.h , A.h B.h.

+7

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


All Articles