我不明白爲什麼我的編譯器是給我的這些錯誤:不能聲明指針「常量類Foo&」錯誤
brain.cpp:16: error: cannot declare pointer to ‘const class FACT&’
brain.cpp: In constructor ‘FACT::FACT(const FACT*)’:
brain.cpp:20: error: cannot convert ‘FACT**’ to ‘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**’ to ‘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**’ to ‘FACT*’ in assignment
brain.cpp:35: error: expected ‘;’ before ‘FACT’
brain.cpp: At 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**’ to ‘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**’ to ‘FACT*’ in initialization
brain.cpp:58: error: expected type-specifier before ‘*’ token
brain.cpp:58: error: cannot convert ‘int**’ to ‘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];
for (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];
for (int x=0; x<=num_relations; x++)
{
copy[x]=relations[x];
}
delete[] relations;
relations=new *FACT[num_relations+1];
for (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];
for (int x=0; x<=num_facts; x++)
{
copy[x]=facts[x];
}
delete[] facts;
facts=new *FACT[num_facts+1];
for (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 is secure");
AddFact(new_item);
delete[] facts;
return 0;
}
我用G ++ 4.4.3我可以「不懂爲什麼它不考慮‘事實’是一種數據類型
我認爲這是如何你做了拷貝構造函數 – noah 2010-11-16 02:09:25
@noah:它沒有'*'。 – sth 2010-11-16 02:15:38