mariusmmg2
mariusmmg2

Reputation: 723

std::pair is calling the default constructor for one of its members

So I have this code line:

statesArray.push_back(std::pair<States, StateSettings>(States::funMode, StateSettings(1, 2, 3, 4, 5, 6)));

statesArray is an object of type QVector<std::pair<States, StateSettings> >.

StateSettings class have this two constructors (from witch the default one is deleted):

StateSettings() = delete;
StateSettings(int a, int b, int c, int d, int e = 0, int f = 0);

When compiling, I get this error:

Error   2   error C2280: 'StateSettings::StateSettings(void)' : attempting to reference a deleted function.

Why std::pair is trying to call the deleted default constructor, if I pass it an object explicitly-constructed with one non-default constructor?

How ho I solve this?

Upvotes: 2

Views: 1298

Answers (1)

Jonathan Mee
Jonathan Mee

Reputation: 38919

As commented by Piotr Skotnicki, the Qt Standard specifies that the value type stored in QVector, and any other Qt Generic container, must:

Be of any assignable data type. To qualify, a type must provide a default constructor, a copy constructor, and an assignment operator.

The value type specified in the question clearly does not meet these qualifications.

One possible way of getting around this would be to store pointers to the values:

QVector<std::pair<States, StateSettings>*> statesArray;

Upvotes: 4

Related Questions