Game !





템플릿 공부하면서 도무지 알 수 없는 에러를 발견하였다




^^...먼소린지...


검색해보니 없는 함수를 불러내서 뜨는 에러라고 한다

그럼 템플릿을 못찾는다는 걸로 볼 수 있는데 왜 안되는지 ㅜ.ㅜ



아래는 에러 뜰 때의 코드..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//////////class.h///////////////
#pragma once
#include <iostream>
using namespace std;
 
class Point
{
private:
    int xpos, ypos;
public:
    Point(int x = 0int y = 0)
        :xpos(x), ypos(y){}
 
    void ShowData() const
    {
        cout << "[" << xpos << ", " << ypos << "]" << endl;
    }
 
    ~Point();
};
 
//////////main.cpp///////////////
template <typename T1>
void SwapData(T1& p1, T1& p2) //레퍼런스
{
    T1 temp;
    temp = p1;
    p1 = p2;
    p2 = temp;
}
 
int _tmain(int argc, _TCHAR* argv[])
{
    Point pos1;
    Point pos2;
 
    SwapData(pos1, pos2);
 
    _getch();
    return 0;
}
 
cs



아무리 찾아봐도 틀린게 없ㅇㅓ서 한참 고민하다가

도움을 받아 알게 되었다


원인은 클래스의 소멸자였다



아래는 클래스의 소멸자를 없앤 코드..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//////////class///////////////
#pragma once
#include <iostream>
using namespace std;
 
class Point
{
private:
    int xpos, ypos;
public:
    Point(int x = 0int y = 0)
        :xpos(x), ypos(y){}
 
    void ShowData() const
    {
        cout << "[" << xpos << ", " << ypos << "]" << endl;
    }
 
    //~Point();
};
 
//////////main///////////////
template <typename T1>
void SwapData(T1& p1, T1& p2) //레퍼런스
{
    T1 temp;
    temp = p1;
    p1 = p2;
    p2 = temp;
}
 
int _tmain(int argc, _TCHAR* argv[])
{
    Point pos1;
    Point pos2;
 
    SwapData(pos1, pos2);
 
    _getch();
    return 0;
}
 
cs



소멸자를 주석하는게 아니라 몸체를 만들어야하는거지만~^^



다시 복습하게 된 점 !


함수에는 꼭 함수의 몸체가 있어야한다! ^_^!! 왜 선언만 해놨을까!!

클래스의 cpp 파일도 안만들었기 때문에 진짜 선언만 해놓은 상태였다.


함수 선언만 하는 경우는 순수가상함수 밖에 없다

외에는 함수의 몸체는 꼭 있어야한다!!!


그래서 저런 에러가 뜬 것이다


꼭꼭 기억하기!