I'm using Visual Studio (not sure if this is relevant here), I want to define a typedef for vector<int>::size_type in a header file.
This is my header:
#ifndef UTILS_H
#define UTILS_H
#include "pch.h"
#include <vector>
typedef int myint;
typedef vector<int>::size_type vi_sz;
#endif //UTILS_H
If I try to build it then I get the following errors:
...\utils.h(8): error C2143: syntax error: missing ';' before '<'
...\utils.h(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
...\utils.h(8): error C2039: 'size_type': is not a member of '`global namespace''
If I move typedef vector<int>::size_type vi_sz; to source file then everything is OK. Note that I don't need to do that with typedef int myint;
Is there a way to define that kind of typedef in header to avoid having to define it for every source file or is this bad practice in some way?