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

Drawing textured cube with Vulkan on Android

glTF loader for Android Vulkan

C++ unit testing & CI integration in GitHub (I/2)