Re: enum problem - getting C4482
"Igor Tandetnik" wrote:
"Stick" <Stick@discussions.microsoft.com> wrote in message
I've got this enum defined in a base class Beverage:
enum SIZE { TALL, GRANDE, VENTI };
switch (this->getSize())
{
case SIZE::TALL:
Enum declaration does not introduce a namespace for its values. They are
in the enclosing namespace - in your case, in the namespace of an
enclosing class. Make it
case TALL:
or, if you want to be exceedingly explicit,
case Beverage::TALL:
Ah, this makes perfect sense. I am explicit as it helps me to see when
'intellisense' in VS doesn't see what I think is there.
What I notice is that if I define Beverage this way:
#pragma once
#include <iostream>
#include <string>
using namespace std;
typedef enum SIZE { TALL, GRANDE, VENTI };
// Class Declaration
class Beverage
{
private:
SIZE size;
string description;
public:
Beverage();
Beverage(string, SIZE);
virtual ~Beverage(void);
virtual void setSize(SIZE);
virtual SIZE getSize();
virtual void setDescription(string);
virtual string getDescription();
virtual double cost() = 0;
};
MS intellisense can't see TALL as a part of the class, and I have to typedef
it as it is a return type for the getSize() function, for example.
So I am thinking I am still doing something wrong. Here is Beverage.cpp too
in case this helps.
#include "Beverage.h"
Beverage::Beverage() { }
Beverage::Beverage(string description, SIZE size)
{
this->description = description;
this->size = size;
}
Beverage::~Beverage() { }
SIZE Beverage::getSize()
{
return this->size;
}
void Beverage::setSize(SIZE size)
{
this->size = size;
}
string Beverage::getDescription()
{
return this->description;
}
void Beverage::setDescription(string description)
{
this->description = description;
}
Thanks, this has been a big help.
Warm regards, Patrick