Friend fumction in C++ class

// in the header file

void changeVar();   // define it.

class testFriend

{

friend void changeVar();  // declare it

private:

     int m_i;

}

// in the cpp file

void changeVar( testFriend&i )  // implement it

{

   i.m_i++;

}

// in the main file

int main()

{

 testFriend test;
 changeVar(test);

}

Comments

Popular posts from this blog

董事長您好

After reading Steve Jobs Autobiography

Drawing textured cube with Vulkan on Android