in Programming
148 views
0 votes
0 votes
A B
class Foo
{
 int i;
 public:
int g()
{return i;}
 int f() 
{return g()+10;}  
 
};
class Foo
{
 int i;
 public:
 int f() 
{return g()+10;} 
 int g()
 {return i;}
};

Select the correct statement.

I.  A and B will be compiled succesfully.

II. A will be compiled but B will cause compilation error as f() calls g() before it is declared.

III. A will cause compilation error as f() calls g() after it is declared.

IV. Both A and B will cause compile error as member functions f() and g() cannot call each other

in Programming
by
148 views

1 Answer

1 vote
1 vote
Both functions will compile successfully because ordering of functions within class declaration doesn't matter and functions can call other functions even declared after them.

Related questions