error C2039: '__ctor' : is not a member of 'UpdateMode'

This is a discussion on error C2039: '__ctor' : is not a member of 'UpdateMode' within the C++ Programming forums, part of the General Programming Boards category; Using VC++ 6.0, if I comment out the StrToUpdateMode() function it compiles fine, but otherwise I get: error C2039: '__ctor' ...

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    error C2039: '__ctor' : is not a member of 'UpdateMode'

    Using VC++ 6.0, if I comment out the StrToUpdateMode() function it compiles fine, but otherwise I get:
    error C2039: '__ctor' : is not a member of 'UpdateMode'
    I have no idea what it's talking about?

    Code:
    namespace UpdateMode
    {
    	enum UpdateMode
    	{
    		AddOnly		= 0,	/**< Only add record if it doesn't already exist. */
    		UpdateOnly	= 1,	/**< Only update record if it exists (i.e. don't add). */
    		AddOrUpdate	= 2,	/**< Update record if it exists, otherwise add a new record. */
    		Delete		= 3	/**< Delete the record. */
    	};
    
    	bool StrToUpdateMode( const TCHAR*  str, UpdateMode::UpdateMode&  updateMode );  // error C2039
    }

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Nevermind, I removed the UpdateMode:: before the UpdateMode parameter and it works. Comeau doesn't have a problem with the original code. VC++ 6.0 bug?

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    More likely VC 6.0 more stringently applies the standard.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Comeau doesn't have a problem with the original code. VC++ 6.0 bug?
    The MinGW port of g++ 3.4.5 does not report any errors or warnings. However, MSVC8 reports that 'UpdateMode::UpdateMode': must be a class or namespace when followed by '::' on line 11.

    I do not know who is correct, but then I usually do not use the same name for an enum as for a namespace.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Since it's inside the namespace, it's not required to explicitly specify the namespace's name within the declaration.
    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.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Since it's inside the namespace, it's not required to explicitly specify the namespace's name within the declaration.
    That's correct, but fully qualifying the name should also be correct, unless the lookup rules state that in that context UpdateMode refers to the enum, so UpdateMode::UpdateMode refers to a member of the UpdateMode enum.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It would refer to the enum.

    You could try ::UpdateMode::UpdateMode instead.

    But really, it's just not good style to give a namespace and a contained element the same name.
    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

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    It would refer to the enum.
    Can you quote the C++ Standard on that? It appears that both Comeau and g++ do not conform, yet MSVC6 does, which is amazing.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Too lazy to look it up, but it seems logical. Of course, the issue wouldn't occur for me, because I make sure my names differ.
    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

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Too lazy to look it up, but it seems logical.
    But the Standard was designed by a committee, and committees can be very illogical at times
    Okay, but so can individuals. Oh well.

    Of course, the issue wouldn't occur for me, because I make sure my names differ.
    Indeed. I think this is the simplest and best solution to the problem.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Yeah, I changed the namespace to UpdateModeNS and it didn't complain about using UpdateModeNS::UpdateMode.
    Strange though, you'd think compilers would be smart enough to know what I'm talking about on each side of the ::

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Why would you think that compilers are smart?
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21