C++ help! *fixed*

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
I have this code..

when compiling through g++ 3.4.2, the line "numbers.push_back(32)" (second last line) generates this error:

19 passing `const std::vector<short int, std::allocator<short int> >' as `this' argument of `void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = short int, _Alloc = std::allocator<short int>]' discards qualifiers

What am I doing wrong? :confused:
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
void splitToVectors(const vector<short> &number, int value) {
number.push_back(32); //why doesnt this work???
}

the reference number is a constant, but push_back modifies number. remove the const qualifier to fix
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Originally posted by: dighn
void splitToVectors(const vector<short> &number, int value) {
number.push_back(32); //why doesnt this work???
}

the reference number is a constant, but push_back modifies number. remove the const qualifier to fix

Thanks :)

Found out why right before you posted! I wish the error messages are less cryptic :frown: