Article View: comp.sys.sgi.bugs
Article #18c++ question/bug?
From: J. Gabriel Foster
Date: Fri, 18 Dec 1992 20:18
Date: Fri, 18 Dec 1992 20:18
105 lines
2794 bytes
2794 bytes
Hello,
I have a question about CC 3.0. I am trying to overload the << function
on a class that is enclosed within another class. As far as I can tell
from Ellis & Stroustrup's "The Annotated C++ Reference Manual" this
is a valid thing to do. For an example of my problem, look at
test1.c and test2.c (given below). test1.c compiles, but test2.c does
not. Why does test2.c not work? My compiler versions and example
source code follow.
Thank you for your time,
--> Gabe Foster
> J. Gabriel Foster (fop@gwha.com)
> GW Hannaway & Associates, 839 Pearl Street, Boulder, CO 80302
> Voice: (303)440-9631, Fax: (303)440-4421
fop@spice<1>versions -n c++
I = Installed, R = Removed
Name Version Description
I c++ 707182570 C++, 3.0
I c++.hdr 1006310004 C++ Headers
I c++.hdr.lib 1006310004 C++ Library Headers
I c++.man 1006310004 C++ Manual Pages
I c++.man.c++ 1006310004 C++ Compiler Man Pages
I c++.man.relnotes 1006310004 C++ Release Notes
I c++.sw 1006310004 C++ Software
I c++.sw.c++ 1006310004 C++ Compiler
I c++.sw.lib 1006310004 C++ Libraries
I c++.sw.libC 1006310004 C++ library
fop@spice<2>cat test1.c
// test1.c
// version WITHOUT name space protection via an enclosing class
class AA {
public:
AA& operator<<( int v ) { v = v; return *this; }
};
class AAA {
friend AA& operator<<( AA& aa, AAA& v );
};
class AAB {
friend AA& operator<<( AA& aa, AAB& v );
};
AA&
operator<<( AA& aa, AAA& v )
{
v = v;
return aa;
}
AA&
operator<<( AA& aa, AAB& v )
{
v = v;
return aa;
}
main( )
{
}
fop@spice<3>CC test1.c
fop@spice<4>cat test2.c
// test2.c
// version WITH name space protection via an enclosing class
class A {
public:
class AA {
public:
AA& operator<<( int v ) { v = v; return *this; }
};
class AAA {
friend AA& operator<<( AA& aa, AAA& v );
};
class AAB {
friend AA& operator<<( AA& aa, AAB& v );
};
};
A::AA&
operator<<( A::AA& aa, A::AAA& v )
{
v = v;
return aa;
}
A::AA&
operator<<( A::AA& aa, A::AAB& v )
{
v = v;
return aa;
}
main( )
{
}
fop@spice<5>CC test2.c
"test2.c", line 25: error: two definitions of operator <<()
fop@spice<6>
Technical Details
Message-ID:
<BzH1r2.BBw@csn.org>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!teal.csn.org!fopShow Full Headers
Complete Article Headers
Newsgroups: comp.sys.sgi.bugs Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!teal.csn.org!fop From: fop@teal.csn.org (J. Gabriel Foster) Subject: c++ question/bug? Message-ID: <BzH1r2.BBw@csn.org> Summary: problem with overloading and enclosed classes Keywords: c++ Sender: news@csn.org (news) Nntp-Posting-Host: teal.csn.org Organization: GW Hannaway & Associates, Inc. Date: Fri, 18 Dec 1992 20:18:34 GMT Lines: 106