type awareness

F

forums_mp

My question I suspect borders on instrospection, in any event
consider the source snippet:

# include <limits>
# include <cmath>
# include <iostream>
# include <vector>

// observer
template <class T>
class Observer {
public:
Observer() {}
~Observer() {}
virtual void Update(T *subject)= 0;
};

// subject
template <class T>
class Subject {
public:
Subject() {}
~Subject() {}
void Attach (Observer<T> &observer) {
m_observers.push_back(&observer);
}
void Notify () {
typename std::vector<Observer<T> *>::iterator it;
for (it=m_observers.begin(); it!=m_observers.end(); it++) {
(*it)->Update(static_cast<T *>(this));
}
}
private:
std::vector<Observer<T> *> m_observers;
};


// SubStationId
class SubStationId : public Subject<SubStationId> {
public:
unsigned int air_bay_invalid;
void SetSubStationId( unsigned int BayNumInvalid) {
air_bay_invalid = BayNumInvalid;
Notify();
}
void Reset () {
air_bay_invalid = 0;
}
};

enum TEST_ENUM_T
{
INVALID = 0,
VALID = 1
};
int main()
{
SubStationId m_station;
// now set sub station id
m_station.SetSubStationId( VALID );
// now retrieve station id
TEST_ENUM_T x;
x = (TEST_ENUM_T )m_station.air_bay_invalid;
std::cout << " Id = x: " << x << std::endl;
return 0;
}

Language rules allows for conversion from enumerated type to int,
however the reverse direction requires a cast. In essense, I have to
say '_from_ which types to convert to which types, and _how_ to
perform the conversion'. My question: Is there a way to make the
parameter air_bay_invalid adaptable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,961
Messages
2,570,130
Members
46,689
Latest member
liammiller

Latest Threads

Top