I'm using enums for the first time to and I'm wondering how best to use them for classes. At the moment I'm encapsulating the meaning within classes (and duplicating for classes that will share it) - but I've run into a problem when assigning a enum type:
class mast {
enum signal { E, G, H, HPLUS, FOURG };
private:
signal capability;
signal current_broadcast;
bool power{ true };
public:
mast();
~mast() = default;
signal getCapability();
signal getBroadcast();
void printCapability();
void printBroadcast();
void setCapability(signal s) {capability = s;}
void setBroadcast(signal s) { current_broadcast = s; }
bool getPower() { return power; }
void setPower(bool b) { power = b; }
};
/*====================================================================================*/
class phone {
enum signal { E, G, H, HPLUS, FOURG };
private:
std::map<std::string,std::string> contacts;
std::map<std::string, std::string> messages;
signal signal_strength;
bool wifi;
public:
phone();
~phone() = default;
void boot(mast& m);
void addContact(std::pair<std::string,std::string>);
bool removeContact(std::string);
void getContacts()
{
for (auto& it : contacts)
{
std::cout << "\nName: " << it.first << "\nNumber: " << it.second << std::endl;
for (int i = 0; i < 20; ++i) std::cout << "-";
}
}
void setSignal(signal s) { signal_strength = s; }
void setWifi(bool b) { wifi = b; }
bool getWifi() { return wifi; }
void searchWifi() {};
};
//==========================================================================================
Are my 2 classes, however in the phone constructor (see error line below) I get the following errors :
error C3867: 'mast::getBroadcast': non-standard syntax; use '&' to create a pointer to member
error C2440: '=': cannot convert from 'mast::signal (__thiscall mast::* )(void)' to 'phone::signal'
#include "phone.h"
#include "mast.h"
#include "rand_eng.h"
phone::phone()
{
wifi = false;
}
void phone::boot(mast& m)
{
signal_strength = m.getBroadcast; // THIS FLAGS ERROR
}
void phone::addContact(std::pair<std::string, std::string> entry)
{
contacts.insert(entry);
}
bool phone::removeContact(std::string entry)
{
std::map<std::string, std::string>::iterator it;
it = contacts.find(entry);
if (it != contacts.end())
{
contacts.erase(it);
return true;
}
return false;
}
Any by the way the code for mast::getBroadcast is:
mast::signal mast::getBroadcast()
{
return current_broadcast;
}
I've also tried putting the enum definition outside of the classes but it still says
error C2440: '=': cannot convert from 'signal (__thiscall mast::* )(void)' to 'signal'