"不完整类型"访问模板类时出错

时间:2014-09-27 13:40:22

标签: android c++ android-ndk java-native-interface incomplete-type

我有一个“SignalProcessingBlock”类,其中包含“Buffer”模板类。 这就是它们的样子:

SignalProcessingBlock.h:

class SignalProcessingBlock{

public:

Buffer <class BufferClass>  *InputBuffer;

Buffer <class BufferClass>  *OutputBuffer;

SignalProcessingBlock   *FrontSignalProcessingBlock;

    void Process();
};

SignalProcessingBlock.cpp:
#include "SignalProcessingBlock.h"
void SignalProcessingBlock::Process()

{
    double tmp;

    for (int i=0;i<(this->InputBuffer->BufferSize/2);i++)

    {

        this->OutputBuffer->buffer[i] = this->InputBuffer->buffer[i*2];

        tmp=this->OutputBuffer->buffer[i];

    }

}

Buffer.h:

template <class BufferClass> class Buffer
{
public:

int         BufferSize;

BufferClass buffer[];

Buffer (BufferClass *buffer,int BufferSize);
};

Buffer.cpp:
#include "Buffer.h"

template <class BufferClass> 

Buffer <BufferClass>::Buffer(BufferClass *buffer,int BufferSize)
{

this->buffer=buffer;

this->BufferSize=BufferSize;
}

甚至在我尝试执行我需要的操作之前,我会得到以下错误行:

jni/SignalProcessingBlock.cpp:34:47: error: definition of implicitly-declared 'SignalProcessingBlock::~SignalProcessingBlock()'
In file included from jni/SignalProcessingBlock.h:4:0,
                 from jni/SignalProcessingBlock.cpp:1:
jni/Buffer.h: In instantiation of 'Buffer<BufferClass>':
jni/SignalProcessingBlock.cpp:42:35:   instantiated from here
jni/Buffer.h:9:21: error: 'Buffer<BufferClass>::buffer' has incomplete type
jni/SignalProcessingBlock.h:11:16: error: forward declaration of 'struct BufferClass'
jni/SignalProcessingBlock.cpp: In member function 'void SignalProcessingBlock::Process()':
jni/SignalProcessingBlock.cpp:44:23: error: 'class Buffer<BufferClass>' has no member named 'buffer'
jni/SignalProcessingBlock.cpp:44:54: error: 'class Buffer<BufferClass>' has no member named 'buffer'
jni/SignalProcessingBlock.cpp:45:27: error: 'class Buffer<BufferClass>' has no member named 'buffer'
/cygdrive/d/Development/NDK/android-ndk-r9/build/core/build-binary.mk:348: recipe for target 'obj/local/armeabi-v7a/objs-debug/com_talkitt_beta_NativeWrapper/SignalProcessingBlock.o' failed
make: *** [obj/local/armeabi-v7a/objs-debug/com_talkitt_beta_NativeWrapper/SignalProcessingBlock.o] Error 1

我用C ++编写并使用eclipse Juno,使用ndk-build(“make”命令包装器)执行调试和构建。

我正在按书完成所有事情并且不理解错误,我确实有“缓冲”成员,语法似乎是正确的。

非常感谢您的帮助!

顺便说一下堆栈溢出告诉我,由于某些原因我需要添加更多信息,所以我只是写东西

1 个答案:

答案 0 :(得分:0)

在模板类Buffer的定义中,标记BufferClass是模板的参数。稍后在声明要使用的Buffer对象的类型时,您需要专门化模板,或者换句话说,指定要用作模板参数的实际类型。

在您的特定情况下,如果您需要包含Buffer值数组的double实例,您可能会执行以下操作:

#include "Buffer.h"
class SignalProcessingBlock{

public:
  Buffer <double>  *InputBuffer;
  ...

另一方面,如果您希望推迟模板专业化,则必须使SignalProcessingBlock也成为模板类:

#include "Buffer.h"
template <class BufferClass> class SignalProcessingBlock{

public:
  Buffer <typename BufferClass>  *InputBuffer;
  ...