7 years, 4 months ago.

CircularBuffer with template is ambiguous error on MDK5 ?

I have built a mbed project with online compiler, which has no complaints at all. However after exporting projects to offline MDK5. I got following complaints. Please advice if anyone knows how to remove/correct such issue.

Compiler complains

SerialInterfaceProtocol/SerialInterfaceProtocol.h(16): error:  #266: "CircularBuffer" is ambiguous
    typedef CircularBuffer<uint8_t> SerialBuffer_t;

AlohaTransceiver/AlohaTransceiver.h(178): error:  #266: "CircularBuffer" is ambiguous
      CircularBuffer<AlohaFrame *> AlohaTxQueue;

AlohaTransceiver/AlohaTransceiver.cpp(44): error:  #266: "CircularBuffer" is ambiguous
  CircularBuffer<AlohaFrame *> AlohaRxQueue(10);

main.cpp(12): error:  #266: "CircularBuffer" is ambiguous
  CircularBuffer<uint8_t> SerialInputBuffer(128);

main.cpp(13): error:  #266: "CircularBuffer" is ambiguous
  CircularBuffer<uint8_t> SerialOutputBuffer(128);

I know CircularBuffer seems ambiguous if it has differenet types, but CircularBuffer is defined as a template, which should be used for different types? And online compiler passed, but MDK5 didn't, is there any compiler options should be enabled ?

The CircularBuffer is defined in RingBuffer.h

RingBuffer.h

#ifndef RINGBUFFER_H_
#define RINGBUFFER_H_

#define DEFAULT_MAX_BUFFER_SZ 64

#include <stdint.h>
#include <stdlib.h>

template <typename T>
class CircularBuffer
{
private:
    const size_t buffer_size;
    size_t read_ptr;
    size_t write_ptr;
    size_t count;
    
    // mutex lock
    bool mux; 
    
    // overflow
    bool is_over_flow;
    
    // container
    T *data;
    
    
public:
    CircularBuffer(const size_t size=DEFAULT_MAX_BUFFER_SZ);
    ~CircularBuffer();
    
    // psudo mutex
    bool isLocked();
    void lock();
    void unlock();
    
    // enqueue and dequeue
    void enqueue(T in);
    T dequeue();
    
    // pointer operation
    size_t getReadPtr();
    size_t getWritePtr();
    size_t getCounter();
    
    // overflow
    bool getOverFlow();
    void clearOverFlow();
    
    // operation
    T first();
    T last();
    
    // random access
    T operator[](size_t idx);
};

#endif

Well, Since most of the RingBuffers are identical in features, just push/pop/isAvaiable and so on. I copied another RingBuffer library into projects, and it works ! Finally I realized such complains may has something to do with mbed/platform/CircularBuffer.h.

The mbed has its own CircularBuffer already, and I included another RingBuffer library, which declared itself as CircularBuffer, that may be the reason why the build system throw out complains, because it has two similiar CircularBuffer in same name.

posted by Kai Liu 27 Jul 2017
Be the first to answer this question.