Reputation: 25
I'm slightly confused about what the difference between these two code examples are in C++
. If anyone could explain it, it would be greatly appreciated.
class abc {
void foo();
};
void abc::foo() {
}
versus something like:
class abc {
void foo() {
//func
}
};
Upvotes: 0
Views: 80
Reputation: 409482
The second alternative implicitly marks the function as inline
, which means you can have it in a header file that is included into multiple translation units.
The first example would break the One Definition Rule if it were part of such a header file.
Upvotes: 2
Reputation: 1697
In the second case the function is by default inline but in other case you need to mention explicitly if you want it inline. Read about inline- Go there
Upvotes: 0