Coding/Tip !!

::연산자와 . 연산자

IMyoungho 2018. 9. 19. 01:08

:: 연산자는 클래스에 사용되고

. 연산자는 객체에 사용된다.




Aclass aa;가 있고 해당 클래스인 Aclass내에 Func 이 정의되어있다면


.연산자는 aa.Func() 객체가 함수를 호출하는데 사용될 수 있으며


::연산자는 void Aclass::Func()으로 클래스를 정의할 떄 사용되거나 static으로 구현된 함수를 클래스에서 호출하는데 사용된다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
 
using namespace std;
 
class Aclass {
public:
    Aclass(){}
    static void Func();
 
private:
};

void Aclass::Func(){
cout << "hello class" << endl;
int main(){
 
    Aclass aa;
    aa.Func();
    Aclass::Func();
 
    return 0;
}

c


반응형