|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> > The book claims that if you write a function body inside a class definition,
> > that makes the method inline. Is this true? I thought there was no
> > difference either way...
> It *has* to be.
It doesn't *have* to be (any more than any other function defined in a
header file, or anywhere else), but the standard says it is, and so it is.
The difference can be seen eg. like this:
//-------- Example 1 ----------
class A
{
public:
// This function is implicitly 'inline',
// no need to specify the keyword:
void foo() { std::cout << "Hello\n"; }
};
//-----------------------------
//-------- Example 2 ----------
class A
{
public:
void foo();
};
// This function is *not* implicitly 'inline' and will cause linker
// errors unless the keyword is used:
void A::foo() { std::cout << "Hello\n"; }
//-----------------------------
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |