* Problems with temporaries and C++ spec
@ 2005-08-27 20:01 Garrett Kajmowicz
2005-08-28 4:45 ` corey taylor
0 siblings, 1 reply; 2+ messages in thread
From: Garrett Kajmowicz @ 2005-08-27 20:01 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Problems with temporaries and C++ spec
2005-08-27 20:01 Problems with temporaries and C++ spec Garrett Kajmowicz
@ 2005-08-28 4:45 ` corey taylor
0 siblings, 0 replies; 2+ messages in thread
From: corey taylor @ 2005-08-28 4:45 UTC (permalink / raw)
To: gkajmowi; +Cc: gcc-help
Why are you using a private copy constructor there in the first place?
corey
On 8/27/05, Garrett Kajmowicz <gkajmowi@tbaytel.net> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-08-28 4:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-27 20:01 Problems with temporaries and C++ spec Garrett Kajmowicz
2005-08-28 4:45 ` corey taylor
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).