Function with enum return type can not be resolved in a class of C++ -
- my check.h file has enum private variable. not know declare enum global entity.
i declare function in check.cpp enum return type. giving error follows.
- multiple markers @ line
- type 'tstatus' not resolved
- ‘tstatus’ not name type
- member declaration not found
my program follows. can please give me solution this.
check.cpp
#include <iostream> #include "check.h" using namespace std; check::check() { } tstatus check::getstatus() { ...... } check::~check() { }
check.h
#ifndef check_h_ #define check_h_ class check { private: enum tstatus { ok,sold,defect }; public: check(); ~check(); tstatus getstatus(); }; #endif /* check_h_ */
firstly, need write
check::tstatus check::getstatus() ^^^^^^^
because otherwise compiler not know tstatus
come from.
see full compilable code here: http://ideone.com/l5qxbk
but note problem. getstatus()
public
function, want call outside of class. not able because return type private
, , can not used outside of class (bar note below). either need make enum public
, or can make getstatus()
private if not used outside of class.
note: can in fact use getstatus()
outside of class tstatus
private — if not use getstatus()
result; see ideone code linked above. though in sensible design such call should not have sense.
also, see vlad's answer on how can use auto
store getstatus()
results tstatus
private. though still better make tstatus
public.
Comments
Post a Comment