c++ - check.cpp file can not recognise enum TStatus, declared in check.h file -


  1. 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.

  2. to solve problem declaring enum global variable, , in check.cpp , check.h files problems solved.

  3. now used function needs check return value form tstatus check::getstatus() value enum.

  4. 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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -