c++ - check.cpp file can not recognise enum TStatus, declared in check.h file -
i declared enum file in check.h file public member of class, problem in check.cpp file used function tstatus check::getstatus() has return type enum. can not resolve tstatus.
to solve problem declaring enum global variable, , in check.cpp , check.h files problems solved.
now used function needs check return value form tstatus check::getstatus() value enum.
this new function not recognise enum because not member of class.
my code follows. please can tell me possible declare enum class member, , can recognised check.cpp file. or there way solve problem.
this check.cpp file
#include <iostream> #include "check.h" using namespace std; check::check() { } tstatus check::getstatus() { return ok; } void check::print() { check object; if(object.getstatus() == tstatus::ok) cout<<"ok"<<endl; if(object.getstatus() == tstatus::sold) cout<<"sold"<<endl; if(object.getstatus() == defect) cout<<"defect"<<endl; } check::~check() { }
this check.h file
#ifndef check_h_ #define check_h_ class check { private: enum tstatus { ok,sold,defect }; public: check(); ~check(); tstatus getstatus(); void print(); }; #endif /* check_h_ */
you declared enum tstatus
in global scope. cannot access via check::ok
. have declared in class.
one way access is
if (object.getstatus() == ok)
, other
if (object.getstatus() == tstatus::ok)
c++11 enum class
required.
better move inside class, ok
somewhere else different.
Comments
Post a Comment