I think this has something to do with the fact that I'm returning a const reference to an object that this function is treating as const.
I think you're smoking crack if you made that connection with the given error. The problem is your syntax in calling size() and at(). Tell me, what is symbol_data.vector ?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
@Narue, maybe it's just a poor choice of variable name?
pseudorandom21
Practically a Posting Shark
890 posts since Jan 2011
Reputation Points: 216
Solved Threads: 111
>>error: ‘template class std::vector’ used without template parameters
This error tells you your problem. You are using std::vector without templates. Why are you confused?
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
I should also clarify, symbol_data is a vector
Then the code should look like this:
string const& symbol::at(int index) const {
assert(index < symbol_data.size());
return symbol_data.at(index);
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Then the code should look like this:
string const& symbol::at(int index) const {
assert(index < symbol_data.size());
return symbol_data.at(index);
}
@OP this might be more clearer:
const string& symbol::at(int index) const {
assert(index < symbol_data.size());
return symbol_data.at(index);
}
So you can read it as 'constant string-reference' instead of 'string const-reference'. Both the produces the same result, take your pick.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
So you can read it as 'constant string-reference' instead of 'string const-reference'.
Which goes against the more consistent policy of reading right to left. Both are valid, and since the OP's code used const on the right, I maintained that style.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Which goes against the more consistent policy of reading right to left. Both are valid, and since the OP's code used const on the right, I maintained that style.
Really? I thought it was more naturally to read things from left to right?
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
I thought it was more naturally to read things from left to right?
Let's give it a try:int x;
x is an int.
int *p;
p is a pointer to int.
int const *p;
p is a pointer to const int.
int const * const p;
p is a const pointer to const int.
Now do the same thing with const to the left and reading left to right:
int x;
int named x.
int *p;
int pointer named p.
const int *p;
const int pointer named p?
const int * const p;
const int pointer that is const named p?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Let's give it a try:
int x;
x is an int.
int *p;
p is a pointer to int.
int const *p;
p is a pointer to const int.
int const * const p;
p is a const pointer to const int.
Now do the same thing with const to the left and reading left to right:
int x;
int named x.
int *p;
int pointer named p.
const int *p;
const int pointer named p?
const int * const p;
const int pointer that is const named p?
I guess I'm just weird then.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608