POV-Ray : Newsgroups : povray.off-topic : Adventures with C++ : Re: An actual C++ question Server Time
29 Jul 2024 04:28:35 EDT (-0400)
  Re: An actual C++ question  
From: Warp
Date: 23 May 2013 11:38:28
Message: <519e37f3@news.povray.org>
Orchid Win7 v1 <voi### [at] devnull> wrote:
> > What do you mean by "field"? Your question is not clear enough.

> I mean something like

>    class Foobar
>    {
>      private:
>        boost::shared_ptr<std::vector<Foo>> foo;
>      public:
>        Foobar()
>    }

Why didn't you say so in the first place?

If you want to initialize that member function in the constructor, use
the constructor's initializer list or just assign to it in the contructor's
body. In the first case:

    Foobar::Foobar(): foo(new std::vector<Foo>)
    {}

Or if you prefer,

    Foobar::Foobar()
    {
        foo = new std::vector<Foo>;
    }

Btw, C++98 does not support >> for closing a double template. You have
to add a space in between.

I'm wondering why you are using a std::vector, though. I thought that what
you wanted was something like this:

//----------------------------------------------------------------

class Foobar
{
    struct Impl;
    boost::shared_ptr<Impl> impl;

 public:
    Foobar();
};
//----------------------------------------------------------------

In which case the implementation would be like:

//----------------------------------------------------------------
struct Foobar::Impl
{
    std::vector<Foo> array;
}

Foobar::Foobar(): impl(new Impl)
{}
//----------------------------------------------------------------

Much simpler and cleaner that way.

> > (And btw, don't start names with an underscore. Those are reserved for
> > the compiler.)

> Hoooookay... In that case, there's about 200 lines in the existing 
> codebase that need to be changed. o_O

I have never quite understood why so many programmers seem to be obsessed
with putting underscores at the beginning of names.

-- 
                                                          - Warp


Post a reply to this message

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