[완료] c++ LNK2019 에러가 떠요 ㅠㅠ.

keke7의 이미지

안녕하세요.
학교 과제물 때문에 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

keke7의 이미지

template는 소스와 해더를 분리해서 넣으면 컴파일이 안된다는군요.;;
결국 task2.cpp에 있는내용을 task2.h 에 넣고 컴파일 했습니다 ..;;

hys545의 이미지

export 키워드가 그런 (?)목적으로 만든건데
http://moogi.new21.org/tc/293?category=4
지금 구현한 컴파일러가 거의 없음

즐린

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.