Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Member function definition outside of class

Is it possible to define function or method outside class declaration? Such as:

class A 
{
    int foo;
    A (): foo (10) {}
}

int A::bar () 
{
    return foo;
}        
like image 938
ska Avatar asked Dec 19 '22 13:12

ska


1 Answers

It is possible to define but not declare a method outside of the class, similar to how you can prototype functions in C then define them later, ie:

class A 
{
    int foo;
    A (): foo (10) {}
    int bar();
}

// inline only used if function is defined in header
inline int A::bar () { return foo; }   
like image 150
Vality Avatar answered Dec 24 '22 01:12

Vality