From: Stick on
I've got this enum defined in a base class Beverage:

enum SIZE { TALL, GRANDE, VENTI };

and the following in a decorator class Mocha
( Beverage <-- CondimentDecorator <-- Mocha )

double Mocha::cost()
{
double cost = this->pBeverage->cost();

switch (this->getSize())
{
case SIZE::TALL:
cost += 0.20;
break;
case SIZE::GRANDE:
cost += 0.25;
break;
case SIZE::VENTI:
cost += 0.30;
break;
default:
cout << "Serious error has occured.";
break;
}
return cost;
}

but when I compile, I get warning C4482 nonstandard extension used: enum
'SIZE' used in qualified name.

What is the compiler trying to tell me? Have I used the enum incorrectly?

Patrick

From: Igor Tandetnik on
"Stick" <Stick(a)discussions.microsoft.com> wrote in message
news:7A79CED2-4C09-4D61-B87D-6765849C1299(a)microsoft.com
> 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:

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: Stick on
"Igor Tandetnik" wrote:

> "Stick" <Stick(a)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

From: Ulrich Eckhardt on
Stick wrote:
> typedef enum SIZE { TALL, GRANDE, VENTI };

What's the typedef doing here?

> class Beverage
> {
[...]
> };
>
> MS intellisense can't see TALL as a part of the class,

TALL isn't part of any class.

> and I have to typedef it as it is a return type for the getSize()
> function, for example.

Using what exact syntax, please? Also, IntelliSense not seeing things does
not mean you have to take any measures, the compiler is the thing to cater
for.

Two more things:
1. There are good reasons to separate macros from non-macros visually, which
is why some people recommend using ALL_UPPERCASE for all macros and only
for those.
2. Scoping enumerations:
namespace size { // as workaround when nesting use a struct
enum type {
...
};
}

Uli

From: Vladimir Grigoriev on
One remark.
IMHO it is not a good idea to use the same names for class variables and for
member function parameters. If someone made a misprint it is difficult to
find such bug.
At least the code
Beverage::Beverage(string theDescription, SIZE theSize)
{
description = theDescription;
size = theSize;
}

looks much better.

Vladimir Grigoriev

"Stick" <Stick(a)discussions.microsoft.com> wrote in message
news:5FFF8A4F-6D60-4665-8E36-16FFABD8B55F(a)microsoft.com...
> Beverage::Beverage(string description, SIZE size)
> {
> this->description = description;
> this->size = size;
> }


 | 
Pages: 1
Prev: _sntprintf and _sntprintf_s
Next: fopen_s