Link to home
Start Free TrialLog in
Avatar of ljmiller
ljmiller

asked on

c++ class & emun

I am a beginner using boreland C++ and am trying to learn out of a book. Using enum and class, i need to create a class decleration for a traffic light. Assume the light can be in one of three states: green, amber, or red. We should be able to check this state or change it. Please help me by creating this class.   thank you ljmiller@cppj.net
Avatar of jaba
jaba

// start header file
class CLight {
protected:
int m_nLightState;
public:
enum STATE {
S_GREEN = 0,
S_AMBER .
S_RED
};
CLight(){};
CLight (intt state ) {m_nLightState = state;};
inline void SetState(int state) {m_nLightState = state;};
inline int GetState const {return m_nLightState};
};

// Start using class
{
CLight lt(lt::S_RED);
lt.SetState(lt:S_AMBER);
....
Thats all

Avatar of ljmiller

ASKER

the class must not have been ran on boreland c++, because it was full of errors likeCompiling NONAME00.CPP:
Error NONAME00.CPP 10: Storage class 'inline' is not allowed here
Error NONAME00.CPP 10: Declaration missing ;
Error NONAME00.CPP 14: Declaration terminated incorrectly

check CLight (intt state ) {m_nLightState = state;};
to
CLight (int state ) {m_nLightState = state;};
I will agree to increase points.
I understand , why you BC compiler generating errors. You need to put class declarations into HEADER file ( noname.h) , when create noname.cpp and include noname.h into it :
#include "noname.h"

void main ()
{
CLight lt(CLight::S_RED);
lt.SetState(CLight:S_AMBER);
}


ASKER CERTIFIED SOLUTION
Avatar of LucHoltkamp
LucHoltkamp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial