Inheritance problem
-
Hi together, I tried to compile the fdstream classes from www.josuttis.com with VC6, but didn't succeed. I cut down the code to what doesn't work:
#include <streambuf>
#include <istream>class mybuf : public std::streambuf
{
protected:
int m_i;
public:
mybuf(int i) : m_i(i) {}
};class myistream : public std::istream
{
protected:
mybuf buf;
public:
myistream(int i) : std::istream(0), buf(i) {}
};int main(int argc, char* argv[])
{
myistream strm(5);
return 0;
}On this code I get the following two errors:
error C2512: 'basic_istream<char,struct std::char_traits<char> >' : no appropriate default constructor available
error C2614: 'myistream' : illegal member initialization: 'istream' is not a base or member
I can't figure out what's the problem. It seemsstd::istream(0)
isn't accepted, but I don't know why. X| Can anyone help me? Thank you very much in advance. Regards, Marcus. -
Hi together, I tried to compile the fdstream classes from www.josuttis.com with VC6, but didn't succeed. I cut down the code to what doesn't work:
#include <streambuf>
#include <istream>class mybuf : public std::streambuf
{
protected:
int m_i;
public:
mybuf(int i) : m_i(i) {}
};class myistream : public std::istream
{
protected:
mybuf buf;
public:
myistream(int i) : std::istream(0), buf(i) {}
};int main(int argc, char* argv[])
{
myistream strm(5);
return 0;
}On this code I get the following two errors:
error C2512: 'basic_istream<char,struct std::char_traits<char> >' : no appropriate default constructor available
error C2614: 'myistream' : illegal member initialization: 'istream' is not a base or member
I can't figure out what's the problem. It seemsstd::istream(0)
isn't accepted, but I don't know why. X| Can anyone help me? Thank you very much in advance. Regards, Marcus.khb wrote:
error C2512: 'basic_istream >' : no appropriate default constructor available
std::istream is a typedef for basic_istream<char, char_traits<char> >. basic_istream has the following constructor:
explicit basic_istream(basic_streambuf *_Strbuf, bool _Isstd = false);
Do you really want your streambuf to be null? If so, try casting 0 as follows:std::istream((std::streambuf*)0);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac -
khb wrote:
error C2512: 'basic_istream >' : no appropriate default constructor available
std::istream is a typedef for basic_istream<char, char_traits<char> >. basic_istream has the following constructor:
explicit basic_istream(basic_streambuf *_Strbuf, bool _Isstd = false);
Do you really want your streambuf to be null? If so, try casting 0 as follows:std::istream((std::streambuf*)0);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week ZacYeah, the streambuf should to be null, as in the original implementation it is replaced by an instance of the inherited streambuffer class using
rdbuf()
. However, casting0
tostd::streambuf*
results in the same errors. If you have another idea on how I get the istream constructor called correctly, I would be really happy. Thank you very much for your help, Marcus. -
Yeah, the streambuf should to be null, as in the original implementation it is replaced by an instance of the inherited streambuffer class using
rdbuf()
. However, casting0
tostd::streambuf*
results in the same errors. If you have another idea on how I get the istream constructor called correctly, I would be really happy. Thank you very much for your help, Marcus.Strange. Not sure why that would be a problem ... I was able to compile your code using g++ with no problems. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Strange. Not sure why that would be a problem ... I was able to compile your code using g++ with no problems. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
I realize that. Generally, GNU is more strick about things like this that Microsoft's compiler. I have VS2005 Pro ... but it doesn't run on Linux, which is what I have to use at work. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
I realize that. Generally, GNU is more strick about things like this that Microsoft's compiler. I have VS2005 Pro ... but it doesn't run on Linux, which is what I have to use at work. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
Sorry Zac, I meant to reply to the original author. VS6 is broken in some ways; I just think that trying to make things work on it is kind of silly when you have a far superior alternative available for free. And the gnu compiler chain is quite nice, but the 3.x series is far superior to VS6 in terms of the probabilty of standard-conforming code compiling and working. earl
-
Sorry Zac, I meant to reply to the original author. VS6 is broken in some ways; I just think that trying to make things work on it is kind of silly when you have a far superior alternative available for free. And the gnu compiler chain is quite nice, but the 3.x series is far superior to VS6 in terms of the probabilty of standard-conforming code compiling and working. earl
earl wrote:
And the gnu compiler chain is quite nice, but the 3.x series is far superior to VS6 in terms of the probabilty of standard-conforming code compiling and working.
Agreed. But sadly, there are many companies that still do all their development in VS6. If the OP hasn't already done so, he might want to download the fixed STL from Dinkumware's site (they are the ones that wrote the version that ships with VS). There were several bugs that were fixed, not sure if this might be one of them. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
earl wrote:
And the gnu compiler chain is quite nice, but the 3.x series is far superior to VS6 in terms of the probabilty of standard-conforming code compiling and working.
Agreed. But sadly, there are many companies that still do all their development in VS6. If the OP hasn't already done so, he might want to download the fixed STL from Dinkumware's site (they are the ones that wrote the version that ships with VS). There were several bugs that were fixed, not sure if this might be one of them. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
Unfortunately, I have to stick to VS6. It's really bad that the behavior might come from bugs in the STL :( Can I simply replace the problematic STL classes? If so, can you provide the Link to the Dinkumware's site? Thank you for you discussion. That brought some light into the dark. I already started thinking that I'm getting to old for understanding C++ ;) Therefore I like your slogan, Zac! Regards, Marcus.
-
Unfortunately, I have to stick to VS6. It's really bad that the behavior might come from bugs in the STL :( Can I simply replace the problematic STL classes? If so, can you provide the Link to the Dinkumware's site? Thank you for you discussion. That brought some light into the dark. I already started thinking that I'm getting to old for understanding C++ ;) Therefore I like your slogan, Zac! Regards, Marcus.
I think Microsoft has a link in MSDN for a service pack download that does it. But here is Dinkumware's site: http://www.dinkumware.com/. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
I think Microsoft has a link in MSDN for a service pack download that does it. But here is Dinkumware's site: http://www.dinkumware.com/. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Unfortunately, I have to stick to VS6. It's really bad that the behavior might come from bugs in the STL :( Can I simply replace the problematic STL classes? If so, can you provide the Link to the Dinkumware's site? Thank you for you discussion. That brought some light into the dark. I already started thinking that I'm getting to old for understanding C++ ;) Therefore I like your slogan, Zac! Regards, Marcus.
Marcus, There is simply quite a bit of valid code that the VS6 compiler is unable to compile. This in turn limits the quality of the STL that can be provided for it. At the end of the day, it's an 8 year old compiler that was written before the C++ standard was finalized IIRC. earl