Community
cancel
Showing results for 
Search instead for 
Did you mean: 
velvia
Beginner
64 Views

Inlining effect on Inside/Outside class definition

Hi,

If you have a method and you want to give the compiler a hint that it is a good idea to inline it, you currently have 2 solutions. The first one is to define the methods when you declare your class:

class Vector {
private:
    double* data_;
    double* size_;
    double* capacity_;
public:
    double& operator[](int k) {
        return data_;
    }
    ...
}

As this method might reduce readability, another solution is to use the inline keyword and define the method out of class:

class Vector {
private:
    double* data_;
    double* size_;
    double* capacity_;
public:
    inline double& operator[](int k);
    ...
}

double& Vector::operator[](int k) {
    return data_;
}

This makes the code more readable (at least I prefer it). Reading my STL implementation, I found that they use a mix of the two. Some methods (those which I think should really be inlined) are defined in the class, and others are defined out of class with the inline keyword. The file also begins with a commented declaration of the class.

So my question is the following. Do Intel compilers are more likely to inline a member function that is declared inside the class than a member function declared out of class with the inline keyword?

0 Kudos
3 Replies
Kittur_G_Intel
Employee
64 Views

Hi,
> So my question is the following. Do Intel compilers are more likely to inline a member function that is declared inside the class than a member function declared out of class with the inline keyword?

The answer is: No, except that sometimes developers tend to use inline keyword for the larger functions, and when a function is larger it is less likely to get inlined

_Kittur.

Cardin_P_
Beginner
64 Views

Faça compiladores da Intel são mais propensos para inline uma função membro que é declarada dentro da classe do que uma função de membro declarado fora da classe com a palavra-chave inline.

Kittur_G_Intel
Employee
64 Views

HI Cardin! 
I've to find someone who can decipher your response! Thanks for the response and hopefully I should find out more on that..
_Kittur

Reply