By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

Deriving from std::basic_streambuf

P: n/a
I can not seem to get this to compile with either gcc 3.4 or MSVC++ .NET
2003... (source follows first):
---= BEGIN MyStreamBuffer.h =---
// #IFDEF redundancy left out.
#include <streambuf>

template< class MyElem >
class MyStreamBuffer : public std::basic_streambuf< MyElem >
{
protected:
int_type overflow( int_type Data = traits_type::eof() );
};

--= END MyStreamBuffer.h =---

---= BEGIN MyStreamBuffer.cpp =---
#include "MyStreamBuffer.h"

template< class MyElem >
int_type MyStreamBuffer::overflow( int_type Data = traits_type::eof() )
{
return 0;
}

---= END MyStreamBuffer.cpp =---

And then I have a basic "int main( /* etc */ )" which merely constructs the
object (without 'new'). I know there's something wrong... as both compilers
I have tried fail to compile the source. I have tried (in the *.cpp file) to
use 'int_type' as "MyStreamBuffer< MyElem >::int_type to no avail.

*If* I leave the definition for the 'overflow' method within the definition
of the class it works no problem (that I can see). I would be very grateful
if someone had a reason why this can't be done... or just a very basic class
that is derived from std::basic_streambuf that has implementation and the
declaration separated by files.

Thank you!
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 08 Aug 2004 06:16:38 GMT, <ye**@twenty.com> wrote:
I can not seem to get this to compile with either gcc 3.4 or MSVC++ .NET
2003... (source follows first):
---= BEGIN MyStreamBuffer.h =---
// #IFDEF redundancy left out.
#include <streambuf>

template< class MyElem >
class MyStreamBuffer : public std::basic_streambuf< MyElem >
{
protected:
int_type overflow( int_type Data = traits_type::eof() );
};

--= END MyStreamBuffer.h =---

---= BEGIN MyStreamBuffer.cpp =---
#include "MyStreamBuffer.h"

template< class MyElem >
int_type MyStreamBuffer::overflow( int_type Data = traits_type::eof() )
{
return 0;
}

---= END MyStreamBuffer.cpp =---

And then I have a basic "int main( /* etc */ )" which merely constructs
the
object (without 'new'). I know there's something wrong... as both
compilers
I have tried fail to compile the source. I have tried (in the *.cpp
file) to
use 'int_type' as "MyStreamBuffer< MyElem >::int_type to no avail.

*If* I leave the definition for the 'overflow' method within the
definition
of the class it works no problem (that I can see). I would be very
grateful
if someone had a reason why this can't be done... or just a very basic
class
that is derived from std::basic_streambuf that has implementation and the
declaration separated by files.

Thank you!


Two things wrong

1) You should not repeat the default argument when you define a function.
Drop ' = traits_type::eof()' from your function definition (but not your
declaration).

2) All template code should go into header files anyway (otherwise you get
linker errors). See the FAQ
http://www.parashift.com/c++-faq-lit...html#faq-34.12

john
Jul 22 '05 #2

P: n/a
"John Harrison" <jo*************@hotmail.com> wrote in message
news:opsceg92pw212331@andronicus...
On Sun, 08 Aug 2004 06:16:38 GMT, <ye**@twenty.com> wrote:
Two things wrong

1) You should not repeat the default argument when you define a function.
Drop ' = traits_type::eof()' from your function definition (but not your
declaration).

2) All template code should go into header files anyway (otherwise you get
linker errors). See the FAQ
http://www.parashift.com/c++-faq-lit...html#faq-34.12
john


Thank you for the quick response. (I thought the inability to separate code
was a problem with old compilers.) I have since been educated... thank you
John.

ty!
Jul 22 '05 #3

P: n/a
On Sun, 08 Aug 2004 06:26:01 GMT, <ye**@twenty.com> wrote:
"John Harrison" <jo*************@hotmail.com> wrote in message
news:opsceg92pw212331@andronicus...
On Sun, 08 Aug 2004 06:16:38 GMT, <ye**@twenty.com> wrote:
Two things wrong

1) You should not repeat the default argument when you define a
function.
Drop ' = traits_type::eof()' from your function definition (but not your
declaration).

2) All template code should go into header files anyway (otherwise you
get
linker errors). See the FAQ

http://www.parashift.com/c++-faq-lit...html#faq-34.12

john


Thank you for the quick response. (I thought the inability to separate
code
was a problem with old compilers.) I have since been educated... thank
you
John.


The export keyword solves this problem, but very few compilers support it.
One that does is Comeau C++.

http://www.comeaucomputing.com/4.0/d...an/export.html

john
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.