error C2512 but i have default constructor available
Jul 3, 2013 at 7:39am UTC
my code have error (error C2512: 'Node' : no appropriate default constructor available) but i have default constructor why ??? my error location commented in code in stat.h Please help me
Node.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#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 );
};
Jul 3, 2013 at 7:52am UTC
i have find this problem.
the problem is circular dependency
Jul 3, 2013 at 7:54am UTC
the problem is that you #include "Node.h" in "stat.h" and "stat.h" in "Node.h"
I suggest that you remove line 2 of "Node.h"
Topic archived. No new replies allowed.