473,666 Members | 2,181 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<Stri ng>
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 <IWAFTraceLin e> >
IWAFTraceLines;

/*************** *************** *************** ***********/
IWAFTraceLine:: IWAFTraceLine( const char* pszFileName, int nLine,
const char* pszLayer,int nError) : m_strFileName.c _str(),
m_nLine,m_strLa yer.c_str(),m_n Error

{
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 1580
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
2006
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
1904
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
5674
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 seen commercial programs print output to the screen as well as to a log file. depending on the user and other situations, i might want to turn off one of the outputs or maybe even both outputs. so, i want a single line with operator << function...
4
2141
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. http://fabrice.marchant.free.fr/LISP/slf/060521/ (For now, my C++ code isn't the result of an object analysis, just a
4
2047
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 other things. What would be a good design to accomplish these goals? Here are the ideas that I have come up with: Class X = class with data that I want to put into csv. 1. Nested Function Object use a nested function object to do the conversion.
1
3496
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 idea? I was under the impression that deriving from std classes that do not have virtual methods was bad. Is ostream designed to be derived from? If, so are there any resources on how to do this properly? ostream has alot if internals that look...
0
1348
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 implementation dependent, since the actual internal format of a float varies between machines. The documentation should specify the format of the float in the file, either by reference to some known format (e.g. IEEE), or by explicitely specifying...
6
2607
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 inside template class definition (commented out at //1) then it compiles and runs fine, but if I declare and define the function separately (at //2). Is the following syntax supported by g++?
0
1257
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
8454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8878
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8785
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7389
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.