Thread: Why this fails - confusing

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    15

    Why this fails - confusing

    please see the comments in code, can someone tell me why it works this way and fails the other way. i was trying to access the elements of the enum nested inside Logger class...
    Code:
    class Logger
    {
    public:
    	enum Level 
    	{
    		Debug, Warn, Error
    	};
    };
    
    int main()
    {
    	cout << Logger::Debug << endl; // Works.
    	cout << Logger::Level::Debug << endl; // Fails!
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Perhaps because the first one is the proper way to do it?

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Because enums are not considered as namespaces, but is placed inside the owning class.
    Therefore the first is valid and the second is invalid.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 06-24-2009, 09:49 AM
  2. Replies: 5
    Last Post: 04-13-2009, 09:55 AM
  3. Mac - File locking with fcntl() fails on shared volumes!?
    By idelovski in forum Linux Programming
    Replies: 3
    Last Post: 11-10-2008, 07:37 PM
  4. Replies: 0
    Last Post: 05-23-2005, 11:39 AM
  5. Beginner Question: CreateWindowEx Fails.
    By dicky in forum Windows Programming
    Replies: 4
    Last Post: 05-30-2004, 08:56 AM