devxlogo

Change the Private Variable Outside of a Member Function Definition

Change the Private Variable Outside of a Member Function Definition

Use the following code to change the private variable outside of a member function definition:

class test{int x;public:test():x(0){}int& getx(){return x;}};int main(){test t(10);cout
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist