POV-Ray : Newsgroups : povray.off-topic : C++ question : Re: C++ question Server Time
28 Jul 2024 16:19:15 EDT (-0400)
  Re: C++ question  
From: Anthony D  Baye
Date: 3 Oct 2013 14:45:00
Message: <web.524dba121cbd09d0328783aa0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> Anthony D. Baye <Sha### [at] spamnomorehotmailcom> wrote:
> > undefined reference to `geometry::operator<<(std::basic_ostream<char,
>
> You have declared that function, but apparently you have not
> implemented it anywhere, therefore the linker cannot find it when
> you try to use it.
>
> >         friend ostream &operator <<(ostream &, const point3d &);
>
> Ostensibly that function will probably not need anything from your
> class that isn't readable through its public interface. It's of course
> not wrong, but it would be better to avoid making it a friend function
> unless there's a good reason for that.
>
> Just declare it as a function inside your 'geometry' namespace
> (and then implement it somewhere, of course.)
>
> --
>                                                           - Warp

I also tried declaring it as a class function:

ostream &operator <<(ostream &);

not realizing, of course that it couldn't be used like it should be... but
-every- example I could find for how to overload the operator properly
(Admittedly, without looking at my textbooks) showed it as a friend.  And it
works that way, but only if the class isn't part of a namespace, which is what
I'm trying to understand...

And while it's true that it wouldn't require anything not available from the
public interface, having it as a friend function allows it to access the private
data members directly without having to resort to a function call.

....

Before replying, I tried moving the declaration to the bottom of the namespace
as an inline function, rather than defining it in point3d.cpp as I had been
doing, but I get the same result when I try to compile uTest.

I'm including my source as a zip file.

Regards,
A.D.B.


Post a reply to this message


Attachments:
Download 'geometry.zip' (4 KB)

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