Mar 21, 2013 at 12:56am Mar 21, 2013 at 12:56am UTC
If I wanted to call a member function inside another member function, how would I do that, if it's possible?
For example, if I have Find(int key) defined already and wanted to call it while i was overloading operator+.
Thanks
Mar 21, 2013 at 1:18am Mar 21, 2013 at 1:18am UTC
Turns out my operator+ has to const which is why I can't.
Mar 21, 2013 at 1:23am Mar 21, 2013 at 1:23am UTC
Just call it.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
struct A
{
int foo( int i ) { std::cout << "A::foo(int)\n" ; return i+3 ; }
int twice_foo( int i ) { return foo(i) * 2 ; }
};
int main()
{
A a ;
std::cout << a.twice_foo(7) << '\n' ;
}
EDIT: > Turns out my operator+ has to const which is why I can't.
Add
const
to
Find(int key)
Last edited on Mar 21, 2013 at 1:26am Mar 21, 2013 at 1:26am UTC