cannot instantiate abstract class

Feb 25, 2011 at 3:50pm
Hi!

I've made these operator overloading functions before but for some reason it is complaining now...

this is what I have.
in header file.
Present ** prsnt;

in cpp file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Handler&Handler::operator=(const Handler & origObj)
{
	for(int i=0;i<this->nrOfPresents;i++)
	{
		delete this->prsnt[i];
	}
	delete [] this->prsnt;

	this->capacity=origObj.capacity;
	this->nrOfPresents=origObj.nrOfPresents;
	this->prsnt=new Present*[origObj.capacity];

	for(int i=0;i<origObj.capacity;i++)
	{
		this->prsnt[i]=NULL;
	}

	for(int i=0;i<origObj.nrOfPresents;i++)
	{
		this->prsnt[i]= new Present(*origObj.prsnt[i]);
	}

	return *this;
}


the error is 'Present' : cannot instantiate abstract class
(last Present)

Best regards. ogward
Feb 25, 2011 at 3:55pm
This has nothing to do with your assignment operator.

What's happening is your 'Present' class has one or more pure virtual functions. You can't instantiate (ie: create with new) classes that have pure virtuals since they're abstract. You can only instantiate derived classes / classes which have no pure virtuals.
Feb 25, 2011 at 6:51pm
oh ok.

but if I have
virtual void presentSpecific()const=0;
as public in my class Present, what can I do?
Feb 25, 2011 at 7:53pm
Feb 26, 2011 at 10:08am
thanks a lot!
I think I solved it with clone().
Topic archived. No new replies allowed.