tags:

views:

98

answers:

2

I am talking about This. Now, my problem is that I have an interface header file which I really don't like to do any implementation in. Can a class derived from a base class declared in that header adopt this idiom? Because as far as I understood, I have to define the (protected) copy constructor for the base class which means that I have to do string (char*) copies. And I don't want to include any headers in my interface header file because of this. Any ideas?

EDIT:

class PluginFunction
{
    public:
        explicit PluginFunction(){}
        virtual ~PluginFunction(){}

        virtual int GetFunctionID() const = 0;
        virtual const char* GetFunctionName() const = 0;

        virtual bool EvalFunction(int&, RNode*, int){return true;}
        virtual bool EvalFunction(double&, RNode*, int){return true;}
        virtual bool EvalFunction(char*&, RNode*, int){return true;}

        virtual PluginFunction* Clone();
    protected:
        explicit PluginFunction(const PluginFunction&)
        {
            //I dont want to strcpy :( which will have to include some header.
            //Or I'll just iterate the buffer myself :).
        }

    private:
        PluginFunction& operator=(const PluginFunction&);

        int i_ID;
        char* z_Name;
};
A: 

Yes a class derived from the base class in that header CAN use that idiom. I'm not sure where you are seeing an issue there.

Goz
+4  A: 

Why can't you put the constructor code in it's own .cpp file? You'll only have to include the relevant str manipulation headers there if needed.

I also don't know why you don't use std::string instead of using raw char pointers. You can always give back the raw pointer using the .c_str() function on it if you really need to.

The only reason why you would need to put everything in the header file including function bodies is if you want them inline or if the class is templated.

David