how to avoid repeating code?

Posted by helloWorld on Stack Overflow See other posts from Stack Overflow or by helloWorld
Published on 2010-06-18T09:27:22Z Indexed on 2010/06/18 9:33 UTC
Read the original article Hit count: 171

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about inline-method