By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,137 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,137 IT Pros & Developers. It's quick & easy.

Can't seem to fix C2259 compile error

P: n/a

Hello

I am getting this compile error:
error C2259: 'PublicTON' : cannot instantiate abstract class due to
following members: csta2less.h(1755) : see declaration of 'PublicTON'

Class is like this:
class PublicTON: public AsnType

generated .h file:
AsnType *Clone() const;

generated .cpp file:
AsnType *PublicTON::Clone() const
{
return new PublicTON(*this);
}

The AsnType class has a clone function like this:
class __declspec(dllexport) AsnType

{

public:

virtual ~AsnType();

virtual AsnType *Clone() const=0;

etc

The clone function is a pure virtual function so I have to implement it.
But I am!

How do I fix this problem?
Angus
Dec 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Angus wrote:
Hello

I am getting this compile error:
error C2259: 'PublicTON' : cannot instantiate abstract class due to
following members: csta2less.h(1755) : see declaration of 'PublicTON'

Class is like this:
class PublicTON: public AsnType
Does this line exist in the definition of PublicTON?
AsnType *PublicTON::Clone() const;

....
>
How do I fix this problem?
Not enough code to see. We can only guess.

Post a complete and compilable chunk o code that demonstrates your
problem. (if the suggested fix above does not work).

Dec 24 '06 #2

P: n/a
Does this line exist in the definition of PublicTON?
AsnType *PublicTON::Clone() const;
mycsta2.h in the PublicTON class there is this line:
AsnType *Clone() const;
Here is the full code (well for this class).

mycsta2.h file has:
class PublicTON: public AsnType
{
public:
enum ChoiceIdEnum
{
unknownCid = 0,
internationalCid = 1,
nationalCid = 2,
networkspecificCid = 3,
subscriberCid = 4,
abbreviatedCid = 5
};
enum ChoiceIdEnum choiceId;
union
{
IA5String *unknown;
IA5String *international;
IA5String *national;
IA5String *networkspecific;
IA5String *subscriber;
IA5String *abbreviated;
};

PublicTON() {Init();}
PublicTON(const PublicTON& that);
public:
virtual const char * typeName(void) const { return "PublicTON"; }
void Init(void);
virtual ~PublicTON() {Clear();}
void Clear();
AsnType *Clone() const;
PublicTON &operator = (const PublicTON &that);
void BDecContent (const AsnBuf &b, AsnTag tag, AsnLen elmtLen, AsnLen
&bytesDecoded/*, s env*/);
void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
};
mycsta2.cpp has:
PublicTON::PublicTON(const PublicTON &that)
{
Init();
*this = that;
}
void PublicTON::Init(void)
{
// initialize choice to no choiceId to first choice and set pointer to NULL
choiceId = unknownCid;
unknown = NULL;
}
void PublicTON::Clear()
{
switch (choiceId)
{
case unknownCid:
delete unknown;
unknown = NULL;
break;
case internationalCid:
delete international;
international = NULL;
break;
case nationalCid:
delete national;
national = NULL;
break;
case networkspecificCid:
delete networkspecific;
networkspecific = NULL;
break;
case subscriberCid:
delete subscriber;
subscriber = NULL;
break;
case abbreviatedCid:
delete abbreviated;
abbreviated = NULL;
break;
} // end of switch
} // end of Clear()
AsnType *PublicTON::Clone() const
{
return new PublicTON(*this);
}
PublicTON &PublicTON::operator = (const PublicTON &that)
{
if (this != &that)
{
Clear();
// Check first type in choice to determine if choice is empty
if (that.unknown != NULL)
{
switch (choiceId = that.choiceId)
{
case unknownCid:
unknown = new IA5String(*that.unknown);
break;
case internationalCid:
international = new IA5String(*that.international);
break;
case nationalCid:
national = new IA5String(*that.national);
break;
case networkspecificCid:
networkspecific = new IA5String(*that.networkspecific);
break;
case subscriberCid:
subscriber = new IA5String(*that.subscriber);
break;
case abbreviatedCid:
abbreviated = new IA5String(*that.abbreviated);
break;
}// end of switch
}// end of if
}
return *this;
}
void PublicTON::BDecContent (const AsnBuf &b, AsnTag tag, AsnLen elmtLen0,
AsnLen &bytesDecoded/*, s env*/)
{
FUNC("PublicTON::BDecContent()");
Clear();
switch (tag)
{
case MAKE_TAG_ID (CNTX, PRIM, 0):
case MAKE_TAG_ID (CNTX, CONS, 0):
choiceId = unknownCid;
unknown = new IA5String;
unknown->BDecContent (b, tag, elmtLen0, bytesDecoded);
break;
case MAKE_TAG_ID (CNTX, PRIM, 1):
case MAKE_TAG_ID (CNTX, CONS, 1):
choiceId = internationalCid;
international = new IA5String;
international->BDecContent (b, tag, elmtLen0, bytesDecoded);
break;
case MAKE_TAG_ID (CNTX, PRIM, 2):
case MAKE_TAG_ID (CNTX, CONS, 2):
choiceId = nationalCid;
national = new IA5String;
national->BDecContent (b, tag, elmtLen0, bytesDecoded);
break;
case MAKE_TAG_ID (CNTX, PRIM, 3):
case MAKE_TAG_ID (CNTX, CONS, 3):
choiceId = networkspecificCid;
networkspecific = new IA5String;
networkspecific->BDecContent (b, tag, elmtLen0, bytesDecoded);
break;
case MAKE_TAG_ID (CNTX, PRIM, 4):
case MAKE_TAG_ID (CNTX, CONS, 4):
choiceId = subscriberCid;
subscriber = new IA5String;
subscriber->BDecContent (b, tag, elmtLen0, bytesDecoded);
break;
case MAKE_TAG_ID (CNTX, PRIM, 5):
case MAKE_TAG_ID (CNTX, CONS, 5):
choiceId = abbreviatedCid;
abbreviated = new IA5String;
abbreviated->BDecContent (b, tag, elmtLen0, bytesDecoded);
break;
default:
throw InvalidTagException(typeName(), tag, STACK_ENTRY);
break;
} // end switch
} // PublicTON::BDecContent

void PublicTON::BDec (const AsnBuf &b, AsnLen &bytesDecoded)
{
AsnLen elmtLen;
AsnTag tag;
/* CHOICEs are a special case - grab identifying tag */
/* this allows easier handling of nested CHOICEs */
tag = BDecTag (b, bytesDecoded);
elmtLen = BDecLen (b, bytesDecoded);
BDecContent (b, tag, elmtLen, bytesDecoded);
}
PrivateTON::PrivateTON(const PrivateTON &that)
{
Init();
*this = that;
}

and the mycsta2.h file #include "asn-incl.h" which has AsnType class like
this:
class SNACCDLL_API AsnType
{
public:
virtual ~AsnType();
virtual AsnType *Clone() const=0;
virtual void BDec (const AsnBuf &b, AsnLen &bytesDecoded)=0;
virtual AsnLen BEnc (AsnBuf &b) const =0 ;
bool BEncPdu (AsnBuf &b, AsnLen &bytesEncoded) const;
bool BDecPdu (const AsnBuf &b, AsnLen &bytesDecoded);
virtual void Print (std::ostream &) const=0;
virtual const char * typeName(void) const { return "AsnType"; }
#if META
static const AsnTypeDesc _desc;
virtual const AsnTypeDesc *_getdesc() const;
virtual AsnType *_getref (const char *membername, bool create=false);
private:
const char *_typename() const;
#if TCL
public:
virtual int TclGetDesc (Tcl_DString *) const;
virtual int TclGetVal (Tcl_Interp *) const;
virtual int TclSetVal (Tcl_Interp *, const char *val);
virtual int TclUnsetVal (Tcl_Interp *, const char *membernames);
#endif // TCL
#endif // META
};
"Gianni Mariani" <gi*******@mariani.wswrote in message
news:45***********************@per-qv1-newsreader-01.iinet.net.au...
Angus wrote:
Hello

I am getting this compile error:
error C2259: 'PublicTON' : cannot instantiate abstract class due to
following members: csta2less.h(1755) : see declaration of 'PublicTON'

Class is like this:
class PublicTON: public AsnType

Does this line exist in the definition of PublicTON?
AsnType *PublicTON::Clone() const;

...

How do I fix this problem?

Not enough code to see. We can only guess.

Post a complete and compilable chunk o code that demonstrates your
problem. (if the suggested fix above does not work).

Dec 24 '06 #3

P: n/a
Angus wrote:
....
class SNACCDLL_API AsnType
{
public:
virtual ~AsnType();
virtual AsnType *Clone() const=0;
virtual void BDec (const AsnBuf &b, AsnLen &bytesDecoded)=0;
virtual AsnLen BEnc (AsnBuf &b) const =0 ;
It seems you don't provide an implementation of BEnc in your derived
class. That would cause the derived class to be abstract and hence
uninstantiable.
Dec 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.