-1

Whenever I try to run my program with the following class, I get an error linked to the declaration of std::stringstream newPredicate; As soon as I remove that declaration (and any uses of it in the source code), the error goes away.

#ifndef LAB1_PREDICATE_H
#define LAB1_PREDICATE_H
#include <sstream>



class Predicate {
private:
public:
    std::stringstream newPredicate;
    void addToString(std::string tokenValue);
    void clearString();
   std::string toString();
};


#endif //LAB1_PREDICATE_H

Below is the source code for the header. I have the stringstream set as a class member so I can access it through any of the functions.

#include "Predicate.h"

void Predicate::addToString(std::string tokenValue) {
    newPredicate << tokenValue;
}

void Predicate::clearString() {
    newPredicate.clear();
}

std::string Predicate::toString() {
    std::string predicateString;
    newPredicate >> predicateString;
    return predicateString;
}

I have a call to a Predicate object a number of times in another class. After I've filled it with the wanted string values, I push it into a vector and clear it.

std::vector<Predicate> myVector;
Predicate myPredicate;
myPredicate.addToString(myString); //I call this function a few times
myVector.push_back(myPredicate);
myPredicate.clearString();

Here's the error message

error: use of deleted function 'Predicate::Predicate(const Predicate&)'
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And then a note

note: 'Predicate::Predicate(const Predicate&)' is implicitly deleted because 
the default definition would be ill-formed:
class Predicate {
      ^~~~~~~~~
Saelyk
  • 9
  • 4

1 Answers1

2

std::stringstream is not copyable therefore the default copy constructor for your Predicate class is not defined.

Presumably somewhere in your code you are trying to copy a Predicate object. You either need to remove the std::stringstream from Predicate, define your own copy constructor or don't copy Predicate objects.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60