0

Hi there,

I hope this is not a major repeat question.

I have a big class and inside it has smaller classes. What I am trying to do is call a function of the outer class from the inner nested class, such as:

class BigClass : public evenBiggerClass
{
int BigClassFunction()
{
return 10;
}
     class SmallNestedClass
    {
         int i = BigClass::BigClassFunction();

     }

};

needless to say I get an error stating ' illegal call on non-static member function' . I do know I could work around it (given the bigger picture of my code). But is there any way I could overcome this directly?

I also know I could declare BigClassFunction() as static but then I cant use other non-static variables in it.

Thanks,

- Denis

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ArkM
0

a little help...

class A
{
	int valueA;
	class B
	{
		int valueB;
	public:
		B(){}
		B(int x):valueB(x)
		{
			std::cout<<"Class B"<<std::endl;
		}
		int get_value()
		{
			return valueB;
		}
	};
public:
	A(){}
	B b;
	A(int x):valueA(x),b(x)
	{
		std::cout<<"Class A"<<std::endl;
	}
	void display(void)
	{
		std::cout<<"Value B "<<b.get_value()<<std::endl;
	}
	
};

int main()
{
    A a(99)
    a.display();
    return 0;
}
0

The inner class does not have special access rights to outer class members, it's not a member of outer class (common misunderstanding of novices). The only effect is that inner class name scope is bounded by outer class. It's the same as ordinar (outside another class definition) class declaration in all other aspects.

Are you surprized at compiler diagnostic message in that case:

class A { ...
public: void f();
};

class B { ...
    void ff() { A::f(); }
}

?
If not, why you don't understand that you have the same case in your snippet?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.