[완료] c++ LNK2019 에러가 떠요 ㅠㅠ.
안녕하세요.
학교 과제물 때문에 template로 doubled link list 클래스를 구현할려고 합니다.
그런데 c++ 라고는 hello world 밖에 않해봐서 도통 이..LNK2019 에러를 어떻게 고쳐야 잡을수 있는지 모르겠습니다
도와주세요 ㅠ
(task2.h)
#ifndef _TASK2_H
#define _TASK2_H
#include <iostream>
#include <string>
using namespace std;
template<typename T>
class task2
{
struct node
{
T data;
node* prev;
node* next;
node(T t, node* p, node* n) : data(t), prev(p), next(n) {}
};
node* head;
node* tail;
public:
task2() : head( NULL ), tail ( NULL ) {}
template<int N>
task2( T (&arr) [N]) : head( NULL ), tail ( NULL )
{
for( int i(0); i != N; ++i)
push_back(arr[i]);
}
bool empty() const { return ( !head || !tail ); }
operator bool() const { return !empty(); }
void push_back(T);
void push_front(T);
T pop_back();
T pop_front();
~task2()
{
while(head)
{
node* temp(head);
head=head->next;
delete temp;
}
}
};
#endif(task2.cpp)
#include <iostream>
#include <string>
#include "task2.h"
using namespace std;
template<typename T>
void task2<T>::push_back(T data)
{
tail = new node(data, tail, NULL);
if( tail->prev )
tail->prev->next = tail;
if( empty() )
head = tail;
}
template <typename T>
void task2<T>::push_front(T data)
{
head = new node(data, NULL, head);
if( head->next )
head->next->prev = head;
if( empty() )
tail = head;
}
template<typename T>
T task2<T>::pop_back()
{
if( empty() )
throw("double_linked : list empty");
node* temp(tail);
T data( tail->data );
tail = tail->prev ;
if( tail )
tail->next = NULL;
else
head = NULL ;
delete temp;
return data;
}
template<typename T>
T task2<T>::pop_front()
{
if( empty() )
throw("double_linked : list empty");
node* temp(head);
T data( head->data );
head = head->next ;
if( head )
head->prev = NULL;
else
tail = NULL;
delete temp;
return data;
}(main.cpp)
#include <iostream>
#include <string>
#include "task2.h"
using namespace std;
int main(int argc, char* argv[])
{
int arr[] = { 4, 6, 8, 32, 19 } ;
task2<int> dlist ( arr );
dlist.push_back( 11 );
dlist.push_front( 100 );
while( dlist )
std::cout << dlist.pop_back() << " ";
std::cout << "\n";
std::string arr2[] = { "a", "bb", "cc", "ddd", "eeee" } ;
task2<std::string> dlist1 ( arr2 );
dlist1.push_back( "gg" );
dlist1.push_front( "ff" );
while( dlist1 )
std::cout << dlist1.pop_back() << " ";
}컴파일 시..
main.obj : error LNK2019: unresolved external symbol "public: class std::basic_string,class std::allocator > __thiscall task2,class std::allocator > >::pop_back(void)" (?pop_back@?$task2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall task2,class std::allocator > >::push_front(class std::basic_string,class std::allocator >)" (?push_front@?$task2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall task2,class std::allocator > >::push_back(class std::basic_string,class std::allocator >)" (?push_back@?$task2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: int __thiscall task2::pop_back(void)" (?pop_back@?$task2@H@@QAEHXZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall task2::push_front(int)" (?push_front@?$task2@H@@QAEXH@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall task2::push_back(int)" (?push_back@?$task2@H@@QAEXH@Z) referenced in function _main
이런 에러가 뜹니다 흑흑..orz


template는 소스와 해더를 분리해서 넣으면
template는 소스와 해더를 분리해서 넣으면 컴파일이 안된다는군요.;;
결국 task2.cpp에 있는내용을 task2.h 에 넣고 컴파일 했습니다 ..;;
템플릿 분리 컴파일은 지금 현재는 불가능합니다.
export 키워드가 그런 (?)목적으로 만든건데
http://moogi.new21.org/tc/293?category=4
지금 구현한 컴파일러가 거의 없음
즐린
댓글 달기