私は3つのパラメータでオブジェクト 'バグバグ'をインスタンス化しようとしています。そのうち1つは列挙子です。ここに私のクラスがあります:C++でenumパラメータを使用してオブジェクトをインスタンス化するにはどうすればよいですか?
class Bug
{
private:
int Id;
string description;
enum severity { low, medium, severe} s;
public:
Bug(void);
Bug(int id, string descr, severity x)
:Id(id), description(descr), s(x)
{}
void printDetails()
{
cout<< "Severity level:" <<s<< " Description: " <<description<<" ID= "
<<Id<< endl;
}
~Bug(void);
}
これは私のmain.cppにある:
#include "Bug.h"
int main(){
Bug bg(3,"a", low);//Error message: identifier "low" is undefined
return 0;
}
私はメイン
enum severity { low, medium, severe};
に次の行を追加したときにエラーメッセージがこれに変更されました:
Bug bg(3,"a", low);//Error message: no instance of constructor "Bug::bug" matches the argument list
任意のアイデアをどのようにこの権利を行うには?公共エリアに
は 'バグを試してみてください:: low'、または'バグ::重症度:: low'を参照してください。 – apalomer
enum定義をpublicセクションに移動します。 main()はそれがprivetであるので、それを見ることができません。 –