polymorphism

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();
}

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.
thanks , how can use abstraction and polymorphism for this class
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.