小编Aja*_*kla的帖子

Why can't I call showA() using A's object?

Why are we able to call the showA() method without object? But if I use void A::showA(A& x) in the method definition then I have to call it using A's object, why?

#include <iostream> 

class A { 

public:
    int a;
    A() { a = 0; } 


     void showA(A&); 
}; 

void showA(A& x) 
{ 

    std::cout << "A::a=" << x.a; 
} 

int main() 
{ 
    A a; 
    showA(a); 
    return 0; 
}
Run Code Online (Sandbox Code Playgroud)

c++ scope-resolution-operator

0
推荐指数
1
解决办法
60
查看次数

标签 统计

c++ ×1

scope-resolution-operator ×1