Why is this default template parameter not allowed?

Posted by Matt Joiner on Stack Overflow See other posts from Stack Overflow or by Matt Joiner
Published on 2011-01-09T11:48:12Z Indexed on 2011/01/09 11:53 UTC
Read the original article Hit count: 311

Filed under:
|
|
|

I have the following class:

template <typename Type = void>
class AlignedMemory {
public:
    AlignedMemory(size_t alignment, size_t size)
        :   memptr_(0) {
        int iret(posix_memalign((void **)&memptr_, alignment, size));
        if (iret) throw system_error("posix_memalign");
    }
    virtual ~AlignedMemory() {
        free(memptr_);
    }
    operator Type *() const { return memptr_; }
    Type *operator->() const { return memptr_; }
    //operator Type &() { return *memptr_; }
    //Type &operator[](size_t index) const;
private:
    Type *memptr_;
};

And attempt to instantiate an automatic variable like this:

AlignedMemory blah(512, 512);

This gives the following error:

src/cpfs/entry.cpp:438: error: missing template arguments before ‘buf’

What am I doing wrong? Is void not an allowed default parameter?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates