简体   繁体   English

访问模板类时出现“不完整类型”错误

[英]“incomplete type” error when accessing a template class

I have a "SignalProcessingBlock" class that contains a "Buffer" template class. 我有一个“ SignalProcessingBlock”类,其中包含“ Buffer”模板类。 This is how they look like: 它们是这样的:

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;
}

Even before I try to perform the actions I need I get the following error lines: 甚至在尝试执行操作之前,我都会出现以下错误行:

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

I am writing in C++ and using eclipse Juno, the debugging and building is performed using ndk-build ("make" command wrapper). 我正在用C ++编写并使用Eclipse Juno,调试和构建使用ndk-build(“ make”命令包装器)执行。

I am doing everything by the book and don't understand the error, I do have the "buffer" member and the syntax seems to be correct. 我正在做本书中的所有事情,并且不了解错误,我确实有“ buffer”成员,并且语法似乎是正确的。

Your help is greatly appreciated! 非常感谢您的帮助!

By the way stack overflow tells me that I need to add some more information for some reason so I am writing just stuff stuff stuff 顺便说一句,堆栈溢出告诉我由于某种原因我需要添加更多信息,所以我只写东西

In the definition of the template class Buffer , the token BufferClass is the parameter of the template. 在模板类Buffer的定义中,标记BufferClass是模板的参数。 Later when declaring the type of Buffer object to be used you need to specialize the template, or in other words specify the actual type to use as the template argument. 稍后,在声明要使用的Buffer对象的类型时,需要专门化模板,或者换句话说,指定要用作模板参数的实际类型。

In your particular case, if you need an instance of Buffer containing an array of double values, you might do something like: 在您的特定情况下,如果您需要一个包含double值数组的Buffer实例,则可以执行以下操作:

#include "Buffer.h"
class SignalProcessingBlock{

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

If on the other hand you wish to defer the template specialization, you would have to make SignalProcessingBlock also a template class: 另一方面,如果您希望推迟模板专业化,则必须使SignalProcessingBlock成为模板类:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM