2013-07-03 3 views
1

내 코드에 오류가 있습니다 (오류 C2512 : '노드': 적절한 기본 생성자를 사용할 수 없음) 하지만 기본 생성자가 있습니까 ??? 코드에서 주석 내 오류 위치는 나에게오류 C2512하지만 기본 생성자를 사용할 수

Node.h

도와주세요
#pragma once 
#include "stat.h" 
#include "Automata.h" 
#include <cstdlib> 

class Node 
{ 
    friend class Automata; 
    friend class stat_a; 
    friend stat_a* makeauto(char *str); 
    friend int main(); 
private: 
    stat_a* mess; 
    char data;//harfi ke ba in masir estefadeh mishe :) 
    Node *next;//node badi dar araye node ha class stat_a :) 
public: 
    Node() 
    { 
     mess = NULL; 
     next = NULL; 
    }; 
}; 

stat.h

#pragma once 
#include "Node.h" 
#include <iostream> 

using namespace std; 
class stat_a 
{ 
    friend class Automata; 
    friend class Node; 
    friend int main(); 
private: 
    bool is_final_stat_a;  //aya final stat_a hast ??? 
    int stat_a_num;    //shomareh halat 0,1,2,... 
    Node *last;     //akharin node dar araye node haye neshan dahande masir 
    Node *first;    //Avalin node dar araye node haye neshan dahande masir 
public: 
    void add(char d,stat_a * a)//ezafeh kardan masiri ke ba estefadeh 
    {      //az harf (char d) be halat (stat_a a) miravad 
     if(first == NULL) 
     { 
      first = new Node;//error is here 
      first->data = d; 
      first->mess = a; 
      last=first; 
     } 
     else 
     { 
      last->next = new Node ;//erorr is here 
      last=last->next; 
      last->data=d; 
      last->next=NULL; 
      last->mess=a; 
     } 
    }; 

    /***********************************************************************/ 

    void print() 
    { 
     cout<<stat_a_num<<"========> is final_stat_a : "<<is_final_stat_a<<endl; 
     Node *a; 

     a=first; 
     while(a != NULL) 
     { 
      cout<<"========> By '"<<a->data<<"' go to stat "<<a->mess->stat_a_num<<endl; 
      a=a->next; 
     } 
    }; 

    stat_a() 
    { 
     last=NULL; 
     first=NULL; 
     is_final_stat_a=false; 
    }; 

    ~stat_a(void); 
}; 

나는 기본 생성자를 사용할 이유 오류

+0

당신이 유래에 도움을 요청합니다 해당 지역의 언어 다음 번에 삭제하시기 바랍니다 의견

Node(); { mess = NULL; next = NULL; } 

, 그것은 언어에 익숙하지 않은 사람들을 위해 단지 소음의 교체 진짜 문제를 산만하게한다. – SpongeBobFan

+0

순환 포함 종속성이 있습니다. 그건 안돼. – juanchopanza

+0

지나치게 친구를 사귀지 말고, 정말로 필요할 때만 지키십시오 (99.99 %의 경우는 절대 안됨). –

답변

10

그것의 고전적인 예입니다 순환 종속성. Node.h 헤더 파일은 stat.h 헤더 파일 Node.h에 따라 달라집니다에 따라 다릅니다. stat.h 헤더에 다음

#pragma once 
#include "Automata.h" 
#include <cstdlib> 

class stat_a; // Declare the class, so the compiler know there's a class by this name 

class Node 
{ 
    // ... 

private: 
    stat_a* mess; // Works because you're only declaring a pointer 

    // ... 

public: 
    // ... 
}; 

:

Node 입력 stat_h의 포인터 변수를 선언하기 때문에, 당신이에 대한 헤더 파일을 포함 할 필요가 없습니다, 그것은 클래스 stat_a를 선언 충분 Node.h을 포함하면 더 이상 순환 종속성이 없습니다.

+0

오, 내 코드 실례지만, 내 코드가 simicolon 아니지만이 오류가 – Rezaagha

+0

@ Rezaagha 내 대답 –

+0

@ 요아킴 Pileborg하지만 여전히 stat.h에 오류 – Rezaagha

1

,

Node() 
{ 
    mess = NULL; 
    next = NULL; 
}; 
+0

내 코드는 내 말은 simicolon 아니지만이 오류가 – Rezaagha

+0

그래서 질문을 편집하십시오 – Simon

관련 문제