The following C++ code is generating this error:
error C2061: syntax error : identifier 'IObject'
Here is my code:
file : IObject.h
#include "IIStreamable.h"
using namespace Serialization;
namespace Object
{
class IObject : public IIStreamable
{
virtual void AcceptReader( IIReader* reader );
virtual void AcceptWriter( IIWriter* writer );
};
}
file: IIWriter
#include "IObject.h"
#using namespace Object;
namespace Serialization
{
class ICORE_API IIWriter
{
public:
// primitive "built in" value types
virtual void writeChar(const char) =0;
virtual void writeUChar(unsigned char) =0;
virtual void writeCharPtr(const char*) =0;
virtual void writeUCharPtr(const unsigned char*) =0;
virtual void writeLong(long) =0;
virtual void writeULong(unsigned long) =0;
virtual void writeShort(short) =0;
virtual void writeUShort(unsigned short) =0;
virtual void writeInt(int) =0;
virtual void writeUInt(unsigned int) =0;
virtual void writeFloat(float) =0;
virtual void writeDouble(double) =0;
virtual void writeBool(bool) =0;
virtual void writeObject(IObject*) =0;
};
}
file: IIStreamable
#include "IIReader.h"
#include "IIWriter.h"
namespace Serialization
{
class ICORE_API IIStreamable
{
public:
virtual void AcceptReader(IIReader*) = 0;
virtual void AcceptWriter(IIWriter*) = 0;
};
}
after compiling this code in vc++ 2010 i got this error
error C2061: syntax error : identifier 'IObject'
in the IIWriter.h file and
error C2061: syntax error : identifier 'IIWriter'
in the IObject.h file and
error C2061: syntax error : identifier 'IIWriter'
in the IIStreamale.h file.
i can not understand why this error occurs?
please help me
thanks
Making use of a using directive as suggested by piokuc will still leave you the problem of a circular include reference
You would be best off changing the IObject.h to the following:
namespace Serialization
{
class ICORE_API IIWriter;
class ICORE_API IIReader;
}
namespace Object
{
class IObject : public IIStreamable
{
virtual void AcceptReader( Serialization::IIReader* reader );
virtual void AcceptWriter( Serialization::IIWriter* writer );
};
}
IE drop the #include and forward declare IIReader and IIWriter. In fact you could avoid more confusion by dropping the #include IObject.h as well and forward declaring that similarly to above....
virtual void writeObject( Object::IObject* ) = 0;
Replace
#using namespace Object;
with
using namespace Object;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With