简体   繁体   中英

“incomplete type” error when accessing a template class

I have a "SignalProcessingBlock" class that contains a "Buffer" template class. 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).

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.

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. 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.

In your particular case, if you need an instance of Buffer containing an array of double values, you might do something like:

#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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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