C++ 是否可以将向量初始化为附加额外元素的另一个向量的副本

C++ 是否可以将向量初始化为附加额外元素的另一个向量的副本,c++,vector,C++,Vector,我有一个静态std::vector的类。我想从它派生,并在派生类中扩展向量 大概是这样的: class A { static std::vector<std::string> column_names; }; std::vector<std::string> A::column_names = {"col1", "col2"}; class B : public A{ static std::vector<std::string> column_na

我有一个静态
std::vector
的类。我想从它派生,并在派生类中扩展向量

大概是这样的:

class A {
  static std::vector<std::string> column_names;
};
std::vector<std::string> A::column_names = {"col1", "col2"};

class B : public A{
  static std::vector<std::string> column_names;
};
std::vector<std::string> B::column_names = {A::column_names, "col2"}; // <-- *
A类{
静态std::向量列名称;
};
std::vector A::column_names={“col1”,“col2”};
B类:公共A{
静态std::向量列名称;
};

std::vector B::column_names={A::column_names,“col2”};// 可以尝试在
B
中使用一个静态函数,该函数返回具有正确值的向量,例如

class B
{
  static std::vector<std::string> initial()
  {
    auto v = A::column_names;
    v.push_back("col2");
    return v;
  }
};
// Now initialize column_names from this function...
std::vector<std::string> B::column_names = B::initial();
B类
{
静态std::vector initial()
{
自动v=A::列名称;
v、 向后推(“col2”);
返回v;
}
};
//现在从此函数初始化列名称。。。
std::vector B::column_names=B::initial();

但是
B
不是从
A
衍生出来的?@Nim我的错误。我忘了打字了。经过编辑,但我认为在这个特殊情况下,它实际上并不重要。看起来是一个很好的简洁的想法,可能很快;并与
const static
一起使用。顺便说一句,我清理了你的代码并接受了。谢谢你的建议。我猜
autov(A::列名称)将是等效的。