I know you can create a list simply with the type list provided by c++ but i need to do a list by using a vector. I think what i am asking is possible but i have no idea how to do it ..
so far i just overloaded [] and = operators so that [] returns the value of the list in the position given and = replaces all elements in the list that are equal to number_to_replace (which is global) with the number next to = .
Code:
#include <iostream>
#include <algorithm>
#include <vector>
//Global variable
int number_to_replace;
class fifo {
vector <int> integervector;
void operator=(int replace_with){
replace(integervector.begin(), integervector.end(), number_to_replace, replace_with);
}
int operator[](int number){
if (integervector.size()>=number)
return integervector[number-1];
else
return -1;
}
};
int main(){
int list_position=0;
//Making an object of type fifo
fifo fifolist;
//Is this possible with overloading ?
//fifolist[list_position]=6
return 0;
}
Any help will be much appreciated (again) !