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?

4

1 回答 1

2

Func在派生类中隐藏所有具有相同名称的基成员。使用using声明性将名称从基类引入派生类。

class Derived : public Base< Derived >
{
public:

    using Base<Derived>::Func;

     //rest..
};
于 2013-08-09T19:55:38.787 回答