S
S
Sergey Ivchenko2015-11-30 21:38:55
OOP
Sergey Ivchenko, 2015-11-30 21:38:55

How to use a pure virtual method inside a class?

I'm trying to define the parent class:

#ifndef OBJECT_H
#define OBJECT_H
#include <sstream>
#include <string>


class Object
{
private :
    virtual void fillBufferForPrint(std::ostringstream &strs) = 0;
public:
    Object();

    operator std::string();

};

#endif // OBJECT_H

#include "object.h"

Object::Object()
{

}

Object::operator std::string() {
    std::ostringstream s;
    fillBufferForPrint(&s);
    return s.str();
}

When I try to build the project, I get the following error:
***/object.cpp:10: error: no matching function for call to 'Object::fillBufferForPrint(std::ostringstream*)'
     fillBufferForPrint(&s);
                          ^

How can this be overcome?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Movchan, 2015-11-30
@Serg89

In the declaration, the method takes a reference, and you pass in a pointer.

fillBufferForPrint(&s); // Нужно не так.
fillBufferForPrint(s);  // А так.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question