c++ - cannot declare pointer to ‘const class FOO&’ error -
i can't understand why compiler giving me these errors:
brain.cpp:16: error: cannot declare pointer ‘const class fact&’ brain.cpp: in constructor ‘fact::fact(const fact*)’: brain.cpp:20: error: cannot convert ‘fact**’ ‘fact*’ in assignment brain.cpp: in member function ‘void fact::addrelation(fact*)’: brain.cpp:29: error: expected type-specifier before ‘*’ token brain.cpp:29: error: cannot convert ‘int**’ ‘fact*’ in initialization brain.cpp:29: error: expected ‘,’ or ‘;’ before ‘fact’ brain.cpp:35: error: expected type-specifier before ‘*’ token brain.cpp:35: error: cannot convert ‘int**’ ‘fact*’ in assignment brain.cpp:35: error: expected ‘;’ before ‘fact’ brain.cpp: @ global scope: brain.cpp:47: error: expected unqualified-id before ‘=’ token brain.cpp:48: error: expected type-specifier before ‘*’ token brain.cpp:48: error: cannot convert ‘int**’ ‘fact*’ in initialization brain.cpp:48: error: expected ‘,’ or ‘;’ before ‘fact’ brain.cpp: in function ‘void addfact(fact*)’: brain.cpp:52: error: cannot convert ‘fact**’ ‘fact*’ in initialization brain.cpp:58: error: expected type-specifier before ‘*’ token brain.cpp:58: error: cannot convert ‘int**’ ‘fact*’ in assignment brain.cpp:58: error: expected ‘;’ before ‘fact’`
#include <iostream> using namespace std; class fact { public: fact(string f) { fact=f; relations=null; num_relations=0; }; ~fact() { delete[] relations; }; fact(const fact& *copy) { num_relations=copy->num_relations; delete[] relations; relations=new fact*[num_relations]; (int x=0; x<=num_relations; x++) { relations[x]=copy->relations[x]; } fact=copy->fact; }; void addrelation(fact *fact) { fact *copy=new *fact[num_relations]; (int x=0; x<=num_relations; x++) { copy[x]=relations[x]; } delete[] relations; relations=new *fact[num_relations+1]; (int x=0; x<=num_relations; x++) { relations[x]=copy[x]; } relations[num_relations+1]=fact; num_relations++; }; string fact; fact *relations; int num_relations; }; fact *facts=new *fact[0]; int num_facts=0; void addfact(fact *new_item) { fact *copy=new fact*[num_facts]; (int x=0; x<=num_facts; x++) { copy[x]=facts[x]; } delete[] facts; facts=new *fact[num_facts+1]; (int x=0; x<=num_facts; x++) { facts[x]=copy[x]; } delete[] copy; num_facts++; facts[num_facts]=new_item; } int main() { fact *new_item=new fact("linux secure"); addfact(new_item); delete[] facts; return 0; }
i'm using g++ 4.4.3 can't understand why doesn't consider "fact" data type
you can't declare pointer reference, try here:
fact(const fact& *copy)
there no such thing pointers reference. wanted reference, without pointer:
fact(const fact& copy)
Comments
Post a Comment