-2
メンバ関数 "print"を使用してベクトル "colors"を出力したいと思います。C++クラス内のベクトルを宣言して初期化する方法
/* Inside .h file */
class Color
{
public:
void print();
private:
std::vector<std::string> colors; = {"red", "green", "blue"};
};
/* Inside .cpp file */
void Color::print()
{
cout << colors << endl;
}
しかし、私はというエラーメッセージが出ます:
Implicit instantiation of undefined template.
ベクトルの宣言と初期化時に "色" クラス本体
、警告の内側:
In class initialization of non-static data member is a C++11 extension.
はあなたの 'の#include'をしましたか?また、ヘッダーファイルで 'colors'と' = 'の間のセミコロンを取り除く必要があります。 –
hlt
そして、C++ 11対応コンパイラ。 –
コンパイラのフラグにC++ 14またはC++ 11を有効にするだけです。しかし、 'std :: vector'に' << 'のオーバーロードがないので、' std :: cout << colors'にはまだ問題があります。 – Quentin