class Vec
{
double dim[];
public:
Vec(void);
~Vec(void);
virtual void Add(Vec vector) = 0;
};
I want to replace the Vec in Vec::Add() with “any class that inherits from Vec“.
Is there a way to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Change the parameter to a reference to const Vec:
A class (publicly) derived from
Veccan be passed by reference to the base class.Also, since you apparently plan to use
Vecas a base class, you probably want to make its dtor virtual too. Otherwise, if you attempt to destroy an object of the derived type via a pointer or reference to the base, you’ll get undefined behavior.