Thread: Unable to see enclosed private class?

  1. #1
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694

    Unable to see enclosed private class?

    I have a class (Quadtree) and three inner class inside (Node, Inner and Leaf). Inner and Leaf inherit from Node.
    I have a function in the private scope of Quadtree.
    All these are located in fun.h .
    Then, in fun.cpp, I am implementing the function (which is named foo <- what a prototype name!), which takes as argument a pointer to an Inner object. Inner seems unable to be resolved however!

    fun.h
    Code:
    class Quadtree {
    private:
    
    class Node{
    public:
            Node() { std::cout << "Node\n"; }
    };
    
    class Inner : public Node {
    public:
            Inner() { std::cout << "Inner\n"; }
            friend class Quadtree;
    };
    
    class Leaf : public Node {
    public:
            Leaf() { std::cout << "Leaf\n"; }
            friend class Quadtree;
    };
    
    
    int foo(Inner* p);
    public:
            Quadtree() { std::cout << "Quadtree\n"; }
    
    };
    fun.cpp
    Code:
    #include <iostream>
    #include "fun.h"
    
    int foo(Inner* p) { std::cout << "foo\n"; }
    px.cpp
    Code:
    #include <iostream>
    #include "fun.h"
    
    int main()
    {
            Quadtree tree;
            return 0;
    }
    Compilation & error:
    Code:
    samaras@samaras-A15:~$ g++ px.cpp fun.cpp -o px
    fun.cpp:4:9: error: ‘Inner’ was not declared in this scope
    fun.cpp:4:16: error: ‘p’ was not declared in this scope
    fun.cpp:4:19: error: expected ‘,’ or ‘;’ before ‘{’ token
    Last edited by std10093; 10-30-2013 at 08:09 PM.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    In fun.cpp it should be Quadtree::foo.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I am ridiculous, sorry...
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Private Class Functions
    By ash4741 in forum C++ Programming
    Replies: 4
    Last Post: 07-27-2009, 08:48 PM
  2. Can Nested class access parent class's private member?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 08:42 AM
  3. Replies: 3
    Last Post: 04-10-2009, 02:20 AM
  4. about private class variables
    By bulletbutter in forum C++ Programming
    Replies: 5
    Last Post: 04-18-2008, 12:13 PM
  5. Private class member not being set
    By cboard_member in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2007, 11:38 AM