S
silversurfer2025
Hello,
I am currently trying to derive a class from ostream (which is giving
output to my GUI), such that I can give my methods either std::cout or
my own outputstream-class to be used as output stream.
Unfortunately, I get a runtime error: "segmentation fault" each time I
am using the overloaded << function but cannot find the mistakt.. Maybe
somebody hwo is more of n expert than me (which shouldn't be too hard)
knows what to change?
///////////////////////////////////////////////////////////////////////////
My header file:
#ifndef _outputstream_
#define _outputstream_
#include <iostream>
#include "FrameWork.h"
class OutputStream : public ostream{
public:
FrameWork* crd;
OutputStream(FrameWork* crd2);
OutputStream& operator <<(int value);
OutputStream& operator <<(double value);
OutputStream& operator <<(char* value);
OutputStream& operator <<(std::string value);
};
#endif /*_outputstream_*/
///////////////////////////////////////////////////////////////////////////
And here is my definition-file .cpp
#include "OutputStream.h"
OutputStream::OutputStream(FrameWork* crd2) {
crd=crd2;
}
OutputStream& OutputStream:perator <<(int value) {
crd->output(0,(double)value);
return *this;
}
OutputStream& OutputStream:perator <<(double value) {
crd->output(0,value);
return *this;
}
OutputStream& OutputStream:perator <<(char* value) {
std::string tmp(value);
crd->output(0,value);
return *this;
}
OutputStream& OutputStream:perator <<(std::string value) {
crd->output(0,value);
return *this;
}
///////////////////////////////////////////////////////////////////////////
The call in the framework-program is:
OutputStream out(this);
out << 4 << "Willkommen!";
and the error I get:
#0 0x0efad884 in std:perator<< <std::char_traits<char> > () from
/usr/lib/libstdc++.so.6
#1 0x1003b0bc in FeatureExtraction::showFeatureConfig
(this=0x10135b40, os=@0x10131830) at ../FeatureExtraction.cpp:243
//this is where I call the << method.
Thanks a lot in advance, I have been trying around for quite some time
now and am looking forward to what you have to say to it.
Greetings
Tim
I am currently trying to derive a class from ostream (which is giving
output to my GUI), such that I can give my methods either std::cout or
my own outputstream-class to be used as output stream.
Unfortunately, I get a runtime error: "segmentation fault" each time I
am using the overloaded << function but cannot find the mistakt.. Maybe
somebody hwo is more of n expert than me (which shouldn't be too hard)
knows what to change?
///////////////////////////////////////////////////////////////////////////
My header file:
#ifndef _outputstream_
#define _outputstream_
#include <iostream>
#include "FrameWork.h"
class OutputStream : public ostream{
public:
FrameWork* crd;
OutputStream(FrameWork* crd2);
OutputStream& operator <<(int value);
OutputStream& operator <<(double value);
OutputStream& operator <<(char* value);
OutputStream& operator <<(std::string value);
};
#endif /*_outputstream_*/
///////////////////////////////////////////////////////////////////////////
And here is my definition-file .cpp
#include "OutputStream.h"
OutputStream::OutputStream(FrameWork* crd2) {
crd=crd2;
}
OutputStream& OutputStream:perator <<(int value) {
crd->output(0,(double)value);
return *this;
}
OutputStream& OutputStream:perator <<(double value) {
crd->output(0,value);
return *this;
}
OutputStream& OutputStream:perator <<(char* value) {
std::string tmp(value);
crd->output(0,value);
return *this;
}
OutputStream& OutputStream:perator <<(std::string value) {
crd->output(0,value);
return *this;
}
///////////////////////////////////////////////////////////////////////////
The call in the framework-program is:
OutputStream out(this);
out << 4 << "Willkommen!";
and the error I get:
#0 0x0efad884 in std:perator<< <std::char_traits<char> > () from
/usr/lib/libstdc++.so.6
#1 0x1003b0bc in FeatureExtraction::showFeatureConfig
(this=0x10135b40, os=@0x10131830) at ../FeatureExtraction.cpp:243
//this is where I call the << method.
Thanks a lot in advance, I have been trying around for quite some time
now and am looking forward to what you have to say to it.
Greetings
Tim