Alvin said:
I'm curious as to your opinions on explicitly inlining function?
They only way to explicitly inline code is to manually inline code.
I'm talking about functions as members of a class.
For example, so class A defines
operator==() and operator!=():
class A {
public:
A(void);
bool operator==(const A& rhs) const;
inline // not necessary
bool operator!=(const A& rhs) const;
// ...
};
inline
bool A:

perator!=(const A& rhs) const {
return !(*this == rhs);
}
Is it something that should be done by the programmer
or should we assume that compiler optimisations will take care of it?
Your compiler may choose to inline operator!= automatically
even if you don't use the inline qualifier.
Your compiler may choose *not* to inline operator!= automatically
even if you *do* use the inline qualifier.
The real purpose of the inline qualifier
is to help the compiler with *linkage*.
If you include your header file in two different translation units
then try to link them together,
you'll get error messages from your link editor:
#ifndef GUARD_CLASS_A_H
#define GUARD_CLASS_A_H 1
class A {
private:
// representation
int I;
public:
// operators
bool operator==(const A& rhs) const;
bool operator!=(const A& rhs) const;
// constructors
A(int i): I(i) { }
};
bool A:

perator!=(const A& rhs) const {
return !(*this == rhs);
}
#endif//GUARD_CLASS_A_H
#include "class_a.h"
bool A:

perator==(const A& rhs) const {
return I == rhs.I;
}
g++ -Wall -ansi -pedantic -c class_a.cpp
cat main.cpp
#include <iostream>
#include "class_a.h"
int main(int argc, char* argv[]) {
A x(13), y(42);
std::cout << (x != y) << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cpp class_a.o
class_a.o(.text+0x0): \
In function `A:

perator!=(A const&) const':
: multiple definition of `A:

perator!=(A const&) const'
/tmp/cc6QaYwA.o(.text+0x100): first defined here
collect2: ld returned 1 exit status
Use the inline qualifier for A:

perator!=
and the problem goes away.