#if my virtual function takes a struct type defined in the base class as a parameter

4 messages · Page 1 of 1 (latest)

abstract smelt
#

should I create a struct type with exactly the same name and definition in the derived class for the override function?

which means the base class and all its derived class need to have the exact same defined struct type if it is used in virtual functions?

slender galleonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

glad oriole
#

provided the struct definition is public, any code can access it and use it to call your virtual function. no need to redefine it

#
class base {
public:
    struct my_struct {};

    virtual void func(my_struct s) = 0;
};

class derived : public base {
    void func(my_struct s) override { /* ... */ }
};

// ...
// Usage

base::my_struct s;
derived d;
d.func(s); // ok