CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2006
    Posts
    134

    Why isn't a base class function visible?

    Greetings!

    I have the following code:

    Base class header file:
    Code:
    class ADODIRECT_API CADODirectRecordset : public CADORecordset
    {
    public:
    	long			GetLastID(const CCOMString& sequenceName);
    }
    Derived class header file:
    Code:
    class _OPERATIONSPLANNERSET_CLASS_EXPORT COperationsTaskSet :
    	public CADODirectRecordset
    {
    public:
    	long GetLastID();
    }
    Derived class implementation:
    Code:
    long COperationsTaskSet::GetLastID()
    {
    	return GetLastID(_T("operations_task_id_seq"));
    }
    When I compile this, my compiler complains that COperationsTaskSet::GetLastID() does not accept 1 argument. I had expected that it would see the one-argument version of GetLastID() defined in the base class. Why doesn't it?

    If I qualify the function name with the base class name, it works:
    Code:
    long COperationsTaskSet::GetLastID()
    {
    	return CADODirectRecordset::GetLastID(_T("operations_task_id_seq"));
    }
    I'm sure I learned about this many years ago, and forgot it. Thank you for refreshing my memory.

    RobR

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Why isn't a base class function visible?

    Quote Originally Posted by
    RobR
    Why isn't a base class function visible?
    The derived class member of the same name hides the base class member. The typical solution is a using declaration:
    Code:
    class _OPERATIONSPLANNERSET_CLASS_EXPORT COperationsTaskSet : public CADODirectRecordset
    {
    public:
        using CADODirectRecordset::GetLastID;
    
        long GetLastID();
    }
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Why isn't a base class function visible?

    Quote Originally Posted by RobR View Post
    When I compile this, my compiler complains that COperationsTaskSet::GetLastID() does not accept 1 argument. I had expected that it would see the one-argument version of GetLastID() defined in the base class. Why doesn't it?

    If I qualify the function name with the base class name, it works:
    This is called name hiding. Basically, the compiler looks in the enclosing scope for the function GetLastID. If it doesn't find it, it looks in the base class (and so on), but if it does find any function named GetLastID then it stops looking for other overloaded functions in further base classes. You can avoid this by adding a using declaration in the derived class.
    Code:
    class _OPERATIONSPLANNERSET_CLASS_EXPORT COperationsTaskSet :
    	public CADODirectRecordset
    {
    public:
    	long GetLastID();
    	using CADODirectRecordset::GetLastID;
    };
    Edit: laserlight really is as fast as the speed of light
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  4. #4
    Join Date
    Aug 2006
    Posts
    134

    Re: Why isn't a base class function visible?

    Thanks very much for your reminders and suggestions.

    RobR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured