1>Compiling...
1>stdafx.cpp
1>gof.cpp
1>e:\projects\stu\gof\gof\bridge.h(62) : error C2512: 'CCustomerDataObject' : no appropriate default constructor available
1>e:\projects\stu\gof\gof\bridge.h(68) : warning C4150: deletion of pointer to incomplete type 'CDataObject'; no destructor called
1> e:\projects\stu\gof\gof\bridge.h(55) : see declaration of 'CDataObject'
1>e:\projects\stu\gof\gof\bridge.h(74) : error C2027: use of undefined type 'CDataObject'
1> e:\projects\stu\gof\gof\bridge.h(55) : see declaration of 'CDataObject'
1>e:\projects\stu\gof\gof\bridge.h(74) : error C2227: left of '->NextRecord' must point to class/struct/union/generic type
1>e:\projects\stu\gof\gof\bridge.h(78) : error C2027: use of undefined type 'CDataObject'
1> e:\projects\stu\gof\gof\bridge.h(55) : see declaration of 'CDataObject'
1>e:\projects\stu\gof\gof\bridge.h(78) : error C2227: left of '->PriorRecord' must point to class/struct/union/generic type
1>e:\projects\stu\gof\gof\bridge.h(82) : error C2027: use of undefined type 'CDataObject'
1> e:\projects\stu\gof\gof\bridge.h(55) : see declaration of 'CDataObject'
1>e:\projects\stu\gof\gof\bridge.h(82) : error C2227: left of '->AddRecord' must point to class/struct/union/generic type
1>e:\projects\stu\gof\gof\bridge.h(86) : error C2027: use of undefined type 'CDataObject'
1> e:\projects\stu\gof\gof\bridge.h(55) : see declaration of 'CDataObject'
1>e:\projects\stu\gof\gof\bridge.h(86) : error C2227: left of '->DeleteRecord' must point to class/struct/union/generic type
1>e:\projects\stu\gof\gof\bridge.h(90) : error C2027: use of undefined type 'CDataObject'
1> e:\projects\stu\gof\gof\bridge.h(55) : see declaration of 'CDataObject'
1>e:\projects\stu\gof\gof\bridge.h(90) : error C2227: left of '->ShowRecord' must point to class/struct/union/generic type
1>e:\projects\stu\gof\gof\bridge.h(95) : error C2027: use of undefined type 'CDataObject'
1> e:\projects\stu\gof\gof\bridge.h(55) : see declaration of 'CDataObject'
1>e:\projects\stu\gof\gof\bridge.h(95) : error C2227: left of '->ShowAllRecords' must point to class/struct/union/generic type
代码如下:
interface CDataObject;
class CCustomerDataObject;
class CCustomersBase
{
public:
CCustomersBase(string group)//:_dataObject(NULL)
{
_dataObject = new CCustomerDataObject();
this->group = group;
}
virtual~CCustomersBase()
{
if(_dataObject != NULL)
delete _dataObject;
}
public:
virtual void Next()
{
_dataObject->NextRecord();
}
virtual void Prior()
{
_dataObject->PriorRecord();
}
virtual void Add(string customer)
{
_dataObject->AddRecord(customer);
}
virtual void Delete(string customer)
{
_dataObject->DeleteRecord(customer);
}
virtual void Show()
{
_dataObject->ShowRecord();
}
virtual void ShowAll()
{
cout<<"Customer Group: " << group<
}
private:
CDataObject *_dataObject;
protected:
string group;
};
class CCustomerObject:public CCustomersBase
{
public:
CCustomerObject(string group="jsss"):CCustomersBase(group)
{
}
public:
// Add separator lines
virtual void ShowAll()
{
cout<<"------------------------"<
cout<<"------------------------"<
};
interface CDataObject
{
public:
virtual void NextRecord() = 0;
virtual void PriorRecord() = 0;
virtual void AddRecord(string name) = 0;
virtual void DeleteRecord(string name) = 0;
virtual void ShowRecord() = 0;
virtual void ShowAllRecords() = 0;
};
class CCustomerDataObject:public CDataObject
{
public:
CCustomerDataObject():_current(0)
{
_customers.push_back("Jim Jones");
_customers.push_back("Samual Jackson");
_customers.push_back("Allen Good");
_customers.push_back("Ann Stills");
_customers.push_back("Lisa Giolani");
}
void NextRecord()
{
if (_current <= _customers.size() - 1)
{
_current++;
}
}
void PriorRecord()
{
if (_current > 0)
{
_current--;
}
}
void AddRecord(string customer)
{
_customers.push_back(customer);
}
void DeleteRecord(string customer)
{
_customers.pop_back();
}
void ShowRecord()
{
cout<<_customers[_current]<
void ShowAllRecords()
{
for(vector
cout<<" "<<*it<
public:
vector
int _current;
};
类似为:interface A;
class B;
class C
{
public:
C(){a = new B;//这里编译不通过,应该是class B与interface只是申明
}
A* a;
};
interface A
{
public:
A(){}
};
class B:public A
{
public:
B(){}
};
int main(int argc, char* argv[])
{ C c;c.a = new B;
}