473,508 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

deriving a class from Ostream

Hi,

I am creating my own class derving from ostream. I am facing problem in
compiling with GNU G++ compiler under linux
class IWCoreEXPORT IWAFTraceLine : public ostream
{
public:
IWAFTraceLine( const char* pszFileName = 0,int
nLine = 0, const char* pszLayer = 0,int nError = -1 );
~IWAFTraceLine( );

IWAFTraceLine( const IWAFTraceLine& that );
IWAFTraceLine& operator = ( const IWAFTraceLine& that );
ostream buffer;

//!!! These numbers can't be negative, so why not uint or size_t?
int getErrorNumber( ) const;
void setErrorNumber( int nError );

int getLineNumber( ) const;
void setLineNumber( int nLine );

const String& getFileName( ) const;
void setFileName( const String& strFileName );

const String& getLayer( ) const;
void setLayer( const String& strLayer );

String getMessage( ) const;

Boolean existsSubstInfo( const String& key ) const;
const String& findSubstInfo( const String& key ) const;
void insertSubstInfo( const String& key,
const String& value );
private:
typedef map< String, String, less < String > ,allocator<String>
SubstInfoMap ;


private:
String m_strFileName;
int m_nLine;
int m_nError;
String m_strLayer;
SubstInfoMap m_substInfo;
strstreambuf m_msg;
};
//!!! Should this be nested within IWAFException??
typedef vector< IWAFTraceLine ,allocator <IWAFTraceLine> >
IWAFTraceLines;

/************************************************** ******/
IWAFTraceLine::IWAFTraceLine( const char* pszFileName, int nLine,
const char* pszLayer,int nError) : m_strFileName.c_str(),
m_nLine,m_strLayer.c_str(),m_nError

{
if(pszFileName)
m_strFileName = pszFileName;

if(pszLayer)
m_strLayer = pszLayer;

init(&m_msg);
}

Can you please tell me that why the code is not been compiled in the
Linux with GNU G++ compiler.

mail me at di*************@hitechclub.com

regards
dinesh

Jul 23 '05 #1
1 1571
hitech_guy wrote:
Hi,

I am creating my own class derving from ostream. I am facing problem in
compiling with GNU G++ compiler under linux
When you are asking for free advice on the net, it's best to give a full
description of what you observed and what you were expecting. What
errors did you receive?


IWAFTraceLine( const IWAFTraceLine& that );
IWAFTraceLine& operator = ( const IWAFTraceLine& that );
ostream does not have copy construction/assignment semantics. You can't
implement anything that would attempt to copy/assign an ostream or
anything containing or derived from it. This is why streams are dealt
with by reference most places.
ostream buffer;


Unless your stream wrapper does little more than wrap the constructor of
a stream, you probably want to investigate writing a custom stream
buffer. The problem is that lots of the functions/operators that take
ostreams will end up taking your IWAFTraceLine and downcasting it to a
ostream& and you'll lose the stuff you added in the derived class.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1993
by: Hans De Winter | last post by:
Hi, I am really puzzled why my compiler does not accept the following code:- --- CODE STARTS HERE --- #include <iostream> using namespace std; class Foo {
3
1887
by: Alicia | last post by:
Hello, I am trying to figure out how to call an overloaded operator<< inherited from a base class. #ifndef PHONECALL #define PHONECALL #include "time.h" #include "interval.h"
2
5661
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have...
4
2133
by: fabricemarchant | last post by:
Hi ! I've translated Andru Luvisi small LISP interpreter sl3.c http://www.sonoma.edu/users/l/luvisi/sl3.c in C++ in order to understand how it works and to experiment with small LISP....
4
2031
by: alacrite | last post by:
I have a class that I want to turn its contents into csv file. I want to be able to set the value of the delimiter, the name of the file it gets saved to, the path of that file, and maybe a few...
1
3483
by: Christopher Pisz | last post by:
I set out to make a custom logger. Examining some other code laying around, I came across one that derived from ostream, and had a associated class derived from streambuf. Is this practice a good...
0
1339
by: James Kanze | last post by:
On 11 avr, 17:44, "mc" <mc_r...@yahoo.comwrote: OK. If the actual format is well documented, that's half the battle won already. Note, however, that reading a float as an int is still very...
6
2595
by: Dan Smithers | last post by:
I want to write my own class derived from the ostream class. I have been getting errors with my templates: First, I get an error writing a nested template. If I leave the function definition...
0
1250
by: ma740988 | last post by:
Consider # include <iostream> # include <vector> # include <typeinfo> # include <string> class BaseMsg { friend std::ostream& operator<<( std::ostream&, const BaseMsg& ); std::string name...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.