-2
class Shapemaker
{
public:
  static Shape * shapeCreate(CDrawView::shape sh);
};

My enum on my CDrawView class is

enum shape{line, rect, elli};
shape current_shape;

when i call Shapemaker::shapeCreate(current_shape) on I get error c2653CDrawView : is not a class or namespace name on shapemaker.h

Shoe
  • 74,840
  • 36
  • 166
  • 272
elFonzo
  • 68
  • 5

5 Answers5

1

This is probably the most plain thing to do:

class Shapemaker{
    public:
    enum Color { //your colors here }
};

class Otherclass{
    void fun(Shapemaker::Color);
};

Now if your compiler does not recognize Shapemaker as a class name, that makes me think you didn't include its header file before declaring Otherclass.

blue
  • 2,683
  • 19
  • 29
  • but when i call fun() what goes inside it. the color red, yellow or fun(red) or an instance of the enum Color. fun(color); – elFonzo Mar 28 '13 at 21:37
  • you can both use fun(Color(red)); or Color mycolor; fun(mycolor); – blue Mar 29 '13 at 00:46
0

If it's an enum member of the other class, then you can reference it as nameoftheClass::Color, but it'd have to be publicly-visible:

void function(nameoftheClass:Color input);
Dan Lecocq
  • 3,383
  • 25
  • 22
  • i try to do that, but when i pass the enum i get a message saying that the class is not a class or a namespace – elFonzo Mar 28 '13 at 21:18
  • "nameoftheclass" is not a class or namespace. i passed the parameter as function(nameofenum) and it gives me that – elFonzo Mar 28 '13 at 21:19
  • Perhaps, then you could add the full declaration of the class where the `enum` is defined, and we can probably be more help – Dan Lecocq Mar 28 '13 at 21:21
  • i added the full declaration of whats happening to me @dan.lecocq – elFonzo Mar 28 '13 at 21:27
0

Say you have as follows:

class C {
    public:
        enum E {
            HERP,
            DERP
        };
 };

A function taking that enum would look like:

void foo(C::E e) {
   // do stuff with e
}
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • say i declare E as em. when i do foo(em) it says that class C is not a namespace or class when i try to compile – elFonzo Mar 28 '13 at 21:22
0

It's all a matter of namespace in the end. Have a look at the answers to this question too, definitively you must not use the keyword enum in the function's parameter list, use directly the enum name with the appropriate namespace.

namespaces for enum types - best practices

Community
  • 1
  • 1
jdehaan
  • 19,700
  • 6
  • 57
  • 97
  • the problem is that when i try to call the function i keep getting an error saying that the class is not a class or namespace – elFonzo Mar 28 '13 at 21:23
  • can you check the new edit that i have made, if you don't mind and if you know why it doesn't work would you mind explaining it? – elFonzo Mar 28 '13 at 21:31
  • I assume you forgot to include the header for `CDrawView` in the file where you are using the static method. – jdehaan Mar 28 '13 at 21:40
0

i tried to pass the color variable enum, but it gives me a compile error saying that the "nameoftheclass" is not a class or namespace

You need to have a declaration placed before you use it, meaning you need proper header files:

MyClass.h

class MyClass {
    public:
        enum Color {
            Red,
            Green,
            Blue
        };
};

MyOtherClass.h

#include "MyClass.h" // This is required.

// Now you can use MyClass::Color freely.
user123
  • 8,970
  • 2
  • 31
  • 52
  • can you check the new edits that i have added @Magtheridon96. I am including CDrawView.h at the top – elFonzo Mar 28 '13 at 21:28