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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

// start header file
class CLight {
int m_nLightState;
enum STATE {
S_GREEN = 0,
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);
Thats all

ljmillerAuthor Commented:
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;};
CLight (int state ) {m_nLightState = state;};
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

ljmillerAuthor Commented:
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);

It's perfectly legal to put class declarations in a .cpp file!
There is a lot of tinkering going on here!
You put them into a header file only if you want other modules (.cpp files) to share the class declaration.

First some remarks on the class CLight:
1. Since you use
   enum STATE { S_GREEN, S_AMBER, S_RED };
   you should not declare the light state-member as
   int m_LightState;
   but as:
   STATE m_LightState;
   to let the compiler help you finding possibly bugs, it will
   complain if you accidentally try to assign an int value to m_LightState

Here's how it should be: (You can put everything in one .cpp file, I did point out how to split it up in a .hpp (header) and
.cpp (module) file.

#include <cstring.h>
class Light
    enum State { Green, Amber, Red }; // the actual values don't matter!!
    State state; // The private variable to hold the State
    Light(State s) : state(s) {}
    void setState(State s)  { state = s; }
    State getState() const  { return state; }
    string asString() const;  // member function is only declared here

// member-function definition (actual code) in light.cpp file
string Light::asString() const
    case Red    : return string("Red");
    case Amber  : return string("Amber");
    case Green  : return string("Green");
  return string("Undefined State!");

// usage (main also in .cpp file, let say main.cpp)
#include <iostream.h>
#include <light.hpp> // not neccesary if you put everything in one file
int main()
  Light light(Light::Green);
  cout <<  light.asString() << endl;
  cout << light.asString() << endl;
  return 0;

Use a project where you put your .cpp files.
Let me know if anything goes wrong.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.