#include <iostream>
#include <string>
using namespace std;
typedef double Money;
string bal;
class Acount
{
public:
Money balance()
{
return bal;//bal的类型?
}
private:
Money bal;
};
int main()
{
return 0;
}
Question: As an example, the type of bal what?
answer:
- When you define a class, the compiler to compile a statement of its members until all visible after the class compiled function body. Because the body of the function bal, so look at the statement;
Money balance()
{
return bal;//bal的类型?
}
- Only statements of balance and bal in class, not declared for the Money, we need to look for enclosing scope Money.
Money balance()
Money bal;
- Money found in the outer scope actually double.
typedef double Money;
Therefore, in the class declaration similar to:
double balance()
double bal;
- From the type declaration type bal it is double, rather than the outermost string.
to sum up:
- When you define a class, the compiler to compile a statement of its members until all visible after the class compiled function body.
- General name lookup procedure: first in the block where the name and the prior use of the name lookup statement code; if not found, the scope continues to look to the outer layer; if the outermost scope did not find a matching name statement, the program error.