error calling a function from a nested class

i have an error calling a function in a class that is inside another class
like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  class first
{
    //function1
    //function2
       class second
          {
            //function3
            //function4
          };
};

int main()
{
  first a;
  a.second.function3();
  return 0;
}


line 15 error..
error: invalid use of 'class first::second'
Last edited on
You didn't give us the error, but my guess is that it was something along the lines of "function3 is not accessible". If that's the error, it is because the default access for class members is private.

In the snippet you posted, class second is private within first and function3 is private within class second.
Last edited on
the second class is inside the public section within the first class .. and all the functions are also public

the error is..
error: invalid use of 'class first::second'
In your code there is no first::second object. And you cannot invoke a function on an object if you have no object.

IOW, if you have:

1
2
3
4
struct A
{
    void func() {}
};


You don't do: A.func();

You do:
1
2
    A a ;
    a.func();
thank you so much cire.. solved by making an object of the inner class like this..

1
2
3
 first::second obj; 

obj.function3();


thank you guys so much.
Last edited on
Topic archived. No new replies allowed.