2010-04-21 2 views
1

이 cpp 파일이 있습니다.C++ 'ClassName Not Declared'오류

dsets.cpp :

#ifndef DSETS_CPP 
    #define DSET_CPP 

    //Adds elements to the DisjointSet data structure. This function adds 
    //x unconnected roots to the end of the array. 
    void DisjointSets::addelements(int x){ 
    } 

    //Given an int this function finds the root associated with that node. 

    int DisjointSets::find(int x){ 
    return 0; 
    } 

    //This function reorders the uptree in order to represent the union of two 
    //subtrees 
    void DisjointSets::setunion(int x, int y){ 

    } 

    #endif 

이 헤더 파일

dsets.h :

#ifndef DSETS_H 
    #define DSET_H 
    #include <iostream> 
    #include <vector> 
    using namespace std; 


    class DisjointSets 
    { 
    public: 
    void addelements(int x); 
    int find(int x); 
    void setunion(int x, int y); 

    private: 
    vector<int> x; 

    }; 

    #include "dsets.cpp" 
    #endif 

그리고 DisjointSets 더 선언하고있다 "고 말을하지 않는 오류가 계속 "
~
~

+0

컴파일 명령은 어떻게 생겼습니까? – James

+2

또한 오타가있는 경우 모르겠지만 #ifndef와 #define에 사용되는 토큰은 동일해야합니다. – Stephen

+2

또 다른 것은 "using namespace ...;" 헤더 파일에. – Stephen

답변

3

당신은 거꾸로 포함하고 있습니다. .cpp 파일의 헤더 파일 (.h)을 포함해야합니다.

.cpp 파일은 컴파일러에서 실제로 컴파일 할 파일입니다. .h 파일은 .cpp 파일에 포함시키기위한 것입니다.

#include .cpp 파일이 없기 때문에 .cpp 파일의 내용에 경비원을 포함 할 필요가 없습니다. (그래도 제한된 상황이있을 수 있지만 일반적인 것은 아닙니다.). 헤더 파일의 내용을 둘러싼 경비 만 필요합니다.

+0

댓글 삭제 : 나는 바보입니다. – Mac

+2

@Mac : 댓글에서 무슨 말을했는지 모르겠지만 당신은 바보가 아니란 걸 확신합니다 :-) –