When I try to build my project, I get the error message " error: no matching function for call to 'Ringbuffer<void*>::Ringbuffer()'
". This is the code that doesn't work, and I wonder why C++ even tries to call " Ringbuffer()
" since I only want to declare an object in Producer
. The constructor of Ringbuffer
takes three arguments. Has anyone an idea? Thanks a lot!
#include "Ringbuffer.h"
class Producer{
private:
Ringbuffer<void*> rbuf;
public:
Producer();
};
Producer::Producer(){
}
why C++ even tries to call "Ringbuffer()"
Because rbuf
is a member of Producer
and when you construct a Producer
that member is constructed as well. If you don't do it explicitly, then rbuf
is implicilty default constructed.
The constructor of Ringbuffer takes three arguments.
When Ringbuffer
has no default constructor (one that can be called without parameter) but only one with 3 arguments, then it cannot be default constructed.
Has anyone an idea?
Call the constructor:
Producer::Producer() : rdbuf(foo,bar,baz) {
}
where foo
, bar
and baz
are the parameters you want to use to construct the Ringbuffer
.
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.