为什么这样写的话,编译器会提示vecsize is not a type
#include <iostream>
#include <vector>
struct A
{
static const int vecSize = 20;
static std::vector<double> vec(vecSize);
};
但如果改成这样就没问题
#include <iostream>
#include <vector>
struct A
{
static const int vecSize = 20;
static std::vector<double> vec;
};
std::vector<double> A::vec(vecSize);
Because
is regarded as a function signature, and the return value is std::vector<double>, so an error occurs when parsing vecSize.
In addition, static non-literal type members in a class need to be initialized outside the class, which is stipulated by C++.
The process of constructing the object type member variable vec must be in the constructor and cannot be constructed when it is declared.