Thread: Funky enum

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Funky enum

    Hello. This is a little portion of some code I have in a header.

    Code:
    class Circle
    {
    public:
    	void move(enum direction d);
    
    private:
    	enum direction { up, down, left, right };
    };

    This is a little portion of code I have in a source file.

    Code:
    void Circle::move(enum direction d)
    {
    	
    }
    I am getting the error

    error C2511: 'void Circle::move(Circle::direction)' : overloaded member function not found in 'Circle'
    This is a little funny, because when I hold my cursor over both the declaration and definition of this function in MSVC 2005, they are exactly the same. Furthermore, if I just say

    Code:
    void move(direction d);
    It gives me the error that it doesn't know what direction is, but I thought this was legal in C++. Any insight is much appreciated!

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Does this work:
    Code:
    class Circle
    {
    private:
    	enum direction { up, down, left, right };
    
    public:
    	void move(direction d);
    
    };
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Don't know, but how 'bout this?
    Code:
    class Circle
    {
       enum direction
       {
          up, down, left, right
       };
    public:
       void move(direction d);
    };
    
    void Circle::move(direction d)
    {
    
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    How is the user supposed to call this public function if the parameter type is private?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Yeah. I was going to ask that and figured to make it public before I left. I'm sure making it public isn't unreasonable so that I can call it like so? Would it just be better to make it global, or is it more modular as it is?

    Code:
    case VK_UP: t.move(Thingy::up);
    Last edited by Tonto; 07-21-2006 at 10:31 AM.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Public or not, it has to be defined before it is used.

    EDIT: I prefer to have them defined inside the class if that's the only context in which they are used.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  2. enum [tag] [: type] Is this non-standard?
    By HyperShadow in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 10:29 PM
  3. enum switchcase and windows message q
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 01:16 PM
  4. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 03:51 AM
  5. enum
    By JerryL in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2004, 05:45 PM