public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Garrett Kajmowicz <gkajmowi@tbaytel.net>
To: gcc-help@gcc.gnu.org
Subject: Problems with temporaries and C++ spec
Date: Sat, 27 Aug 2005 20:01:00 -0000	[thread overview]
Message-ID: <200508271604.35552.gkajmowi@tbaytel.net> (raw)

I'm working on my own C++ library for embedded applications (cxx.uclibc.org) 
and while implementing valarray I came across a problem with private copy 
contructors.  The following code works in GCC 3.3.5, but not in GCC 3.4.2

#include <iostream>

class copy_to;

class hidden_copying{
public:
        friend class copy_to;
        friend class copy_from;

private:
        hidden_copying() : q(0) {  }
        hidden_copying(const hidden_copying &);
        hidden_copying & operator=(const hidden_copying &);
        int q;
};

class copy_to{
public:
        friend class copy_from;
        copy_to() : p (0) { }
        copy_to(const hidden_copying & h) : p(h.q) {  }
        int getval() const{
                return p;
        }
private:
        int p;
};

class copy_from{
public:
        friend class hidden_copying;
        copy_from() : r(0) {  }
        copy_from(const int i) : r(i) {  }
        copy_from(const copy_from & f) : r(f.r) {  }
        hidden_copying data() const{
                hidden_copying retval;
                retval.q = r;
                return retval;
        }

private:
        int r;
};


int main(){
        copy_from a(5);
        copy_to b(a.data());
        std::cout << "Value of copy_to: " << b.getval() << std::endl;
        return 0;
}

With gcc 3.4.2 I receive the following error message:
../temporarytest.cpp: In function `int main()':
../temporarytest.cpp:12: error: `hidden_copying::hidden_copying(const 
hidden_copying&)' is private
../temporarytest.cpp:48: error: within this context

Without breaking valarray spec (in the above case, amounting to making any of 
the copy constructors of hidden_copying public), how can I get the above code 
work work properly.   If There is no way, than please explain how to 
reconsile behaviors with spec definition of std::slice_array.

Thank you for your help.

-     Garrett

             reply	other threads:[~2005-08-27 20:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-27 20:01 Garrett Kajmowicz [this message]
2005-08-28  4:45 ` corey taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200508271604.35552.gkajmowi@tbaytel.net \
    --to=gkajmowi@tbaytel.net \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).