Bug 50533 - Can not scope ostream within a class
Can not scope ostream within a class
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-07-31 19:21 EDT by Dan Mergens
Modified: 2007-04-18 12:35 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-07-31 19:34:40 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Dan Mergens 2001-07-31 19:21:01 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.2.16-22 i686)

Description of problem:
The compiler prevents scoping ostream as a method of a class.

How reproducible:
Always

Steps to Reproduce:
compile the following code:
-----------------------------------
#include <iostream.h>
 
class Debug
{
private:
        ostream*    _os;
 
public:
        Debug() : _os( &cout ) {}
        ostream&    ostream() { return *_os; }
};
 
int
main( int argc, char* const* argv )
{
        Debug debug;
 
// cout default output
        debug.ostream() << "Debug stuff\n";
}

Actual Results:  tst_debug.o tst_debug.C
tst_debug.C:10: declaration of `ostream &Debug::ostream ()'
/usr/include/g++-3/iostream.h:45: changes meaning of `ostream' from
`class ostream'
gmake: *** [tst_debug.o] Error 1

Expected Results:  compile should be successful, when run produce the
following results:
---------------------------------------
Debug stuff

Additional info:

This code will work on IRIX 6.5 using CC.
Comment 1 Dan Mergens 2001-07-31 19:34:36 EDT
Problem exists on both gcc 2.96-85 and 2.96-94
Comment 2 Jakub Jelinek 2001-08-09 06:24:04 EDT
Unqualified ostream must have only one meaning in the class.
You must write std::ostream where they mean that. If it was not a classname
from std namespace but from global namespace (such as a class defined by you),
then you just would need to add :: before it.
#include <iostream.h>

class Debug
{
private:
        std::ostream*    _os;

public:
        Debug() : _os( &cout ) {}
        std::ostream&    ostream() { return *_os; }
};

int
main( int argc, char* const* argv )
{
        Debug debug;

// cout default output
        debug.ostream() << "Debug stuff\n";
}
should work just fine.

Note You need to log in before you can comment on or make changes to this bug.