POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days : Re: Days 5- Server Time
30 Jul 2024 00:31:16 EDT (-0400)
  Re: Days 5-  
From: Warp
Date: 20 Apr 2012 08:11:12
Message: <4f915260@news.povray.org>
Darren New <dne### [at] sanrrcom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.