mercredi 29 septembre 2021

how to inherit and resue the std::tuple function from base class in C++?

class common: public NotImportant
{
   public :
   common(); //default constuctor
   explicit common(xxx);
   
   ~common();

   virtual std::tuple<a,b> funcA();
   virtual void funcB();
   void  xx1();
   void  xx2();
   void  xx3();
   void  xx4();
}

class special: public base
{
   public :
   explicit special(xx);
   ~special()
   virtual void funcB() override;
}

The class common implemented all the functions, and the virtual funcA() is a pure virtual function in class Notimportant.

The class special will reuse all the implemented functions from class common except funcB, so the funcB will only be implemented for this class.This method i have used for long time and it works fine to reuse the functions in class common.

But now the problem is the return type of funcA in class common is std::tuple<a,b>, so when i compile the code i have one error:

error #2045: function "funcA" requires a virtual table thunk but its return type, "std::tuple<a, b>", is incomplete. 
Please ensure that "***std::tuple<a, b>***" is defined/instantiated in this translation unit. 

may i know how to solve it? is inherited class required to add sth like template for reuse std::tuple function?

this funcA must use std:tuple as it's a interface from the other class.

And the way i build is to write the make file to include the source file of class common.

Aucun commentaire:

Enregistrer un commentaire