Pointer/Reference to Class within a Class within a Class
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Pointer/Reference to Class within a Class within a Class

  1. #1
    Join Date
    Oct 2012
    Posts
    15

    Pointer/Reference to Class within a Class within a Class

    I have encountered a problem I can't see to solve. I want to access a function and can't seem to find the right combination to get me there. Here is what I am looking at:

    CFoo1::CFoo2::GetStrDataC(int nRow) const

    How do I call the GetStrDataC function from another class?

    Thanks for the help!

    John

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,271

    Re: Pointer/Reference to Class within a Class within a Class

    Is it a static function?
    Is it declared as public?
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2012
    Posts
    15

    Re: Pointer/Reference to Class within a Class within a Class

    It is a helper class in a Protected area. Not Static.

    John

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,271

    Re: Pointer/Reference to Class within a Class within a Class

    Could you show the declarations?
    Victor Nijegorodov

  5. #5
    Join Date
    Oct 2012
    Posts
    15

    Re: Pointer/Reference to Class within a Class within a Class

    //------------------------------------------------------------------------
    // Summary:
    // This is helper class designed to manage a set of strings
    //------------------------------------------------------------------------
    class _EXT_CLASS CFooStringsManager
    {
    //{{AFX_CFOO_PRIVATE
    friend class CFooEditBufferManager;
    //}}AFX_CFOO_PRIVATE
    public:

    //----------------------------------------------------------------------
    // Summary:
    // Default object constructor.
    //----------------------------------------------------------------------
    CFooEditStringsManager();

    //----------------------------------------------------------------------
    // Summary:
    // Default object destructor. Handles cleanup and deallocation
    //----------------------------------------------------------------------
    virtual ~CFooEditStringsManager();

  6. #6
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Pointer/Reference to Class within a Class within a Class

    Quote Originally Posted by JohnWHagen View Post
    //------------------------------------------------------------------------
    // Summary:
    // This is helper class designed to manage a set of strings
    //------------------------------------------------------------------------
    class _EXT_CLASS CFooStringsManager
    {
    //{{AFX_CFOO_PRIVATE
    friend class CFooEditBufferManager;
    //}}AFX_CFOO_PRIVATE
    public:

    //----------------------------------------------------------------------
    // Summary:
    // Default object constructor.
    //----------------------------------------------------------------------
    CFooEditStringsManager();

    //----------------------------------------------------------------------
    // Summary:
    // Default object destructor. Handles cleanup and deallocation
    //----------------------------------------------------------------------
    virtual ~CFooEditStringsManager();
    1) Please use code tags when posting code.

    2) When you get a compiler error, it helps to post the complete code that doesn't compile, and not a description of what doesn't compile.

    3) That function must be a static function, since you cannot just call a non-static member function without an instance of the object.

    I can get your situation to compile very easily, but I bet it isn't what you actually are trying to compile:
    Code:
    class CFoo1
    {
       public:
       class CFoo2
       {
           public:
               void GetStrData() const;
       };
       CFoo2 foo2;
    };
    
    int main()
    {
       CFoo1 theFoo;
       theFoo.foo2.GetStrData();
    }
    There is no need for the scope resolution operator, as you must have a CFoo2 object (the foo2 member) to use the inner class. So show how your code differs in form to the code above.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Oct 2012
    Posts
    15

    Re: Pointer/Reference to Class within a Class within a Class

    Thanks for the sample code. It does explain some of what I did not know.

    The code I am trying to understand is from a commercial vendor. I purchased it three years ago and they have since moved on to an updated version. After some digging I did find the problem I am having was not an error on my part but one they did not detect. An updated patch solved my problem.

    This too is what I did not upload much of the code or the compiler error. I don't need issues with companies balking about exposing their source code (I paid for it) and don't need the legal eagles headed my way.

    Thanks to you both for the assistance. It helps those of us who learn much of this on our own. Somedays we make great progress. Other days it may only be a line or two of code. I enjoy the challenges but really take pride in the successes!

    John

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center