2014-09-15 3 views
1

멤버 함수 오류와 같은 포인터와 나는 다음과 같은 오류를 얻을 :나는 다음과 같은 멤버 함수를 만들기 위해 노력하고

class ListStudentGradeDB 
{ 

private: 


public: 
    struct node 
    { 
     std::string studentName; 
     int studentScore; 
     node *next; 

    }; 
    // line below is to create shortcut to node* nodePtr. 
    typedef struct node* nodePtr; 

    nodePtr head; 
    nodePtr curr; 
    nodePtr temp; 


    // Constructor 
    ListStudentGradeDB(); 


    // member functions for merge sort 
    void MergeSort(); 
    nodePtr msort(nodePtr start, int size); 
    nodePtr merge(nodePtr list1, nodePtr list2, int size1, int size2); 

    // Destructor 
    ~ListStudentGradeDB(void); 


}; 



    //ListStudentGradeDB.cpp 

    nodePtr ListStudentGradeDB::msort(node* start, int size) 
    { 
     if(size > 1) 
     { 
      int midSize = size/2; 
      int count = midSize; 
      node* mid = start; 
      while(count) 
     { 
      mid = mid->next; 
      count--; 
     } 
     return merge(msort(start, midSize), msort(mid, size - midSize), midSize, size - midSize); 
    } 
    else 
     return start; 
} 


nodePtr ListStudentGradeDB::merge(nodePtr list1, nodePtr list2, int size1, int size2) 
{ 
    // Trivial cases 
    if(size1 == 0) 
     return list2; 

    if(size2 == 0) 
     return list1; 

    // Choose the bigger element from the front of the two lists 
    // and put it at the head of the new list and call merge 
    // again with the sub lists 

    if (list1->studentScore < list2->studentScore || list1->studentScore == list2->studentScore) 
    { 
     list1->next = merge(list1->next, list2, size1-1, size2); 
     return list1; 
    } 
    else 
    { 
     list2->next = merge(list1, list2->next, size1, size2-1); 
     return list2; 
    } 
} 

오류

 
> 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(534): error 
> C2143: syntax error : missing ';' before 'ListStudentGradeDB::msort' 
> 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(534): error 
> C4430: missing type specifier - int assumed. Note: C++ does not 
> support default-int 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(535): error 
> C4430: missing type specifier - int assumed. Note: C++ does not 
> support default-int 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(535): error 
> C2556: 'int ListStudentGradeDB::msort(ListStudentGradeDB::node *,int)' 
> : overloaded function differs only by return type from 
> 'ListStudentGradeDB::nodePtr 
> ListStudentGradeDB::msort(ListStudentGradeDB::nodePtr,int)' 1>   
> c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.h(88) : see 
> declaration of 'ListStudentGradeDB::msort' 
> 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(535): error 
> C2040: 'ListStudentGradeDB::msort' : 'int (ListStudentGradeDB::node 
> *,int)' differs in levels of indirection from 'ListStudentGradeDB::nodePtr (ListStudentGradeDB::nodePtr,int)' 
> 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(546): error 
> C2264: 'ListStudentGradeDB::msort' : error in function definition or 
> declaration; function not called 1>c:\users\vypham\documents\visual 
> studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(553): error 
> C2143: syntax error : missing ';' before 'ListStudentGradeDB::merge' 
> 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(553): error 
> C4430: missing type specifier - int assumed. Note: C++ does not 
> support default-int 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(553): error 
> C2086: 'int nodePtr' : redefinition 1>   
> c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(534) : see 
> declaration of 'nodePtr' 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(554): error 
> C4430: missing type specifier - int assumed. Note: C++ does not 
> support default-int 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(554): error 
> C2556: 'int 
> ListStudentGradeDB::merge(ListStudentGradeDB::nodePtr,ListStudentGradeDB::nodePtr,int,int)' 
> : overloaded function differs only by return type from 
> 'ListStudentGradeDB::nodePtr 
> ListStudentGradeDB::merge(ListStudentGradeDB::nodePtr,ListStudentGradeDB::nodePtr,int,int)' 
> 1>   c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.h(89) : see 
> declaration of 'ListStudentGradeDB::merge' 
> 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(554): error 
> C2040: 'ListStudentGradeDB::merge' : 'int 
> (ListStudentGradeDB::nodePtr,ListStudentGradeDB::nodePtr,int,int)' 
> differs in levels of indirection from 'ListStudentGradeDB::nodePtr 
> (ListStudentGradeDB::nodePtr,ListStudentGradeDB::nodePtr,int,int)' 
> 1>c:\users\vypham\documents\visual studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(568): error 
> C2264: 'ListStudentGradeDB::merge' : error in function definition or 
> declaration; function not called 1>c:\users\vypham\documents\visual 
> studio 
> 2012\projects\cmpe_180\cmp180_final\liststudentgradedb.cpp(573): error 
> C2264: 'ListStudentGradeDB::merge' 

나는 두 멤버 함수에 대한 포인터를 반환하려합니다. 누구든지 도울 수 있니?

+1

'nodePtr'은 선언 된 클래스의 일부입니다. 클래스를 벗어난 구현에서 반환 유형에 대해'ListStudentGradeDB :: nodePtr'을 시도 했습니까? – WhozCraig

답변

0

nodePtr에는 클래스 범위가 있으므로 ListStudentGradeDB.cnp 정의에 ListStudentGradeDB :: nodePtr을 써야합니다.

0

문제가 당신의 기능의 구현과 거짓말을 상당히 가능성이 보인다

nodePtr ListStudentGradeDB::merge(... 

nodePtr이 단지 merge처럼 ListStudentGradeDB에 정의되어 있습니다. 따라서 다음과 같이 해당 범위에 액세스해야합니다.

ListStudentGradeDB::nodePtr ListStudentGradeDB::merge(... 
+0

감사합니다. 완벽하게 작동합니다. – Victor

+0

@ 빅터 멋진데, 그것을 올바르게 표시하는 것을 고려하십시오! –

관련 문제