polymorphism

Aug 23, 2010 at 10:47am
Hi . I created this class but when I created object from class my compiler return error invalid abstract return type for function 'Academisions aca()
class University
{
public:
University();
virtual void setInfo() = 0 ;
virtual void getInfo() = 0 ;
protected:
string faculty;
};

class Academisions : public University
{
public:
Academisions();
string getId();
string getName();
string getDegree();
virtual void setInfo();
private:
string id;
string name;
string degree;
};

int main()
{
Academisions aca();
}

Aug 23, 2010 at 11:01am
1
2
3
4
int main()
{
Academisions aca();   //compilers think that it function declaration(function has name 'aca', that does not take params and return value with Academisions type by value, it means that copy constructor will be involved, but it's abstrcat class and con not be created.
}

Solution, where you create object by default constructor, please don't use '()'
1
2
3
4
int main()
{
Academisions aca; //compiler error, but there is another problem, see below
}


But your class Academisions does not implement virtual void getInfo() = 0 ; method from base class, so you could not create object.
Aug 23, 2010 at 12:51pm
thanks , how can use abstraction and polymorphism for this class
Aug 23, 2010 at 12:59pm
You need to implement both pure virtual functions in the subclass Academisions. Then you need to access those functions through a pointer or a reference to an object of type Univertity.
Topic archived. No new replies allowed.