how to avoid repeating code?
- by helloWorld
I have some technical question, I have repeating code in my work, and I want to get rid of it, so I know that in C++ it is not good idea to use macro, but instead I must use inline function, is it good idea to use this function as inline:
list<Data>::iterator foo(int data){
if(dataExists(data)){
    list<Data>::iterator i;
    for(i = Data.begin(); i != Data.end(); ++i){
       if(i->getData() == data){
        break;
       }
return i;   //here I have one more problem, what can I return if data doesn't exist?
}
I'm beginner, and I think that this function is very unsafe, can somebody please give me advice, how can I improve my code, thanks in advance
P.S. what usually do You use to avoid repeating code?