POV-Ray : Newsgroups : povray.off-topic : C++ question : Re: C++ question Server Time
28 Jul 2024 22:29:16 EDT (-0400)
  Re: C++ question  
From: Warp
Date: 3 Oct 2013 17:55:49
Message: <524de7e5@news.povray.org>
Anthony D. Baye <Sha### [at] spamnomorehotmailcom> wrote:
> At any rate, defining it as warp mentioned using the inline keyword seems to
> work

The inline keyword has nothing to do with why it works. It's there for
a different reason.

The key is that the function has to be on the outer scope, it cannot be
inside the class. What the 'friend' function declaration does is to
simply say that the function in question can read the private members
of the class. You still have to implement the function outside.

If the function doesn't need to read the private members of the class,
then the 'friend' declaration is pretty obsolete and should be avoided
to keep the code cleaner.

>, but according to what I've read, that just gives the compiler a hint that
> it can be copied in wherever it's called rather than being called as a function.

Actually, 'inline' is an instruction for the linker, but that's another
story, unrelated to the problem you were having.

> Anyway, the program compiles now, I just wish I could find out why it was being
> so stubborn with the friend function of a class contained in a namespace.

The 'friend' declaration inside the class is not enough by itself. It's
simply telling that a function with that signature can access the private
section of the class.

-- 
                                                          - Warp


Post a reply to this message

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