Can Virtual Classes in C++ have Member Variables?

Absolutely.

Strictly speaking, there is no such thing as a “virtual class”. I understand that you are using the term to mean a class constructed of only data members and virtual member functions.

Consider that only functions can be virtual; if you wish for data members to be accessed polymorphically, you must do this through functions. Thus, use virtual getter/setter functions, and keep your data members private.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)