1

So thanks to this answer I'm looking at implementing my problem with CRTP. However I have a problem. In my static base class I have 2 sets of functions. One takes std::vectors and one takes a standard C-style array. So in the base class I define a static function that calls the non-std::vector function.

However when I derive from that base class I seem to no longer be able to access the public static function in the base class (Which I thought I could).

template< class Derived > class Base
{
public:
    static void Func( std::vector< float >& buffer )
    {
       Func( &buffer.front(), buffer.size() );
    }

    static void Func( float* pBuffer, int size )
    {
        Derived::Func( pBuffer, size );
    }
};

I then define the derived class as follows:

class Derived : public Base< Derived >
{
public:
    static void Func( float* pBuffer, int size )
    {
        // Do stuff
    }
};

However when I try to call the static function in the Base class:

Derived::Func( stlVec );

From the Derived class it throws a compilation error:

error C2665: 'main' : none of the 2 overloads could convert all the argument types
1>          c:\development\Base.h(706): could be 'void Func( float*, int )

I assumed that I would be able to call a public static defined in the base class from the Derived class. This appears not to be the case, however ... Can anyone suggest a workaround that doesn't mean having to implement the std::vector function in every one of my Derived classes?

Community
  • 1
  • 1
Goz
  • 61,365
  • 24
  • 124
  • 204

1 Answers1

2

Func in the derived class hides all base members with the same name. Use using declarative to bring the names from the base class into the derived class.

class Derived : public Base< Derived >
{
public:

    using Base<Derived>::Func;

     //rest..
};
Nawaz
  • 353,942
  • 115
  • 666
  • 851
  • Oh damn ... I thought it would only hide if it took the same parameters ... what a pain :( Is it possible to import ALL the base classes functions using a "using Base< Derived >"? – Goz Aug 09 '13 at 20:09
  • @Goz: `using` declarative brings *name* into the scope. So you have to mention *which* name. – Nawaz Aug 09 '13 at 20:12
  • And thats a "no" in answer to my question ... Seems a pain to have to put that using statement for every function though :( – Goz Aug 09 '13 at 20:13
  • @Goz: Not every *function*. It is every *name*, i.e `using Base::Func;` will bring ALL members (whether they're functions, data, or types) with *same* name to the current scope. – Nawaz Aug 09 '13 at 20:17
  • Alas, in my case it will be every function :( – Goz Aug 09 '13 at 20:25