Re: Problems with temporaries and C++ spec

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Why are you using a private copy constructor there in the first place?

corey

On 8/27/05, Garrett Kajmowicz <gkajmowi@xxxxxxxxxxx> wrote:
> 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
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux