One day when writing classes suddenly thought of this problem, the following to explain how to solve the problem.
Define a class:
class test{public: void setnum (); void getnum (); Private : int num;}; void Test::setnum () { ten;} void Test::getnum () { printf ("%d\n", num);}
Run:
int Main () { test one; One.setnum (); One.getnum (); return 0 ;}
Console output 100, which indicates that member functions can be directly modified by the member variables without relying on parameter arguments .
Next we can make a change to the member function of the assignment:
#include <stdio.h>#include<windows.h>#include<mysql.h>classtest{ Public: voidSetnum (intx); voidgetnum ();Private: intnum;};voidTest::setnum (intx) {num=x;}voidTest::getnum () {printf ("%d\n", num);}intMain () {test one; One.setnum ( -); One.getnum (); return 0;}
Console output 100
Let's make another change:
class test{public: void setnum (int num); void getnum (); Private : int num;}; void test::setnum (int num) { = num;}
At this point in the run, the member function that found the assignment is not running at all.
The solution is:
void test::setnum (int num) { this->num = num;}
Use this pointer to distinguish between the two variables.
The problem of coincidence of parameter names and member variable names of member functions in C + +