473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Deriving from std::basic_streambuf

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
3 3421
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Vinokur | last post by:
Is it possible to use vector<ostringstream> ? Here is what I have got. =========================================== Windows 2000 CYGWIN_NT-5.0 1.3.22(0.78/3/2) GNU gcc version 3.2 20020927...
3
by: Steven T. Hatton | last post by:
I'm a bit confused about a statement in TC++ST §13.10. It's in reference to this example: /* The following code example is taken from the book * "The C++ Standard Library - A Tutorial and...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
1
by: Johannes Barop | last post by:
Hello, i try to implement a streambuffer. I overwrote streambuf::overflow() and streambuf::xsputn(). Both are protected and virtual (http://www.cplusplus.com/ref/iostream/streambuf/). But...
6
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
2
by: bosse | last post by:
Hi, i have got a linker problem, i don't know how to handle; there are three projects in my workspace. In the Project called modules_common is a class called Features. In the second project...
2
by: sri | last post by:
Dear All, I would like to implement file buffer class to make avialable buffering mechanism to ifstream or own customized file stream. My question is what are the semantics for seekoff,...
7
by: Christopher Pisz | last post by:
I found an article http://spec.winprog.org/streams/ as a starting point, but it seems to do alot of things that aren't very standard at all. One particular problem is, that he is using a vector as...
2
by: Arcturus | last post by:
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkh6waMACgkQq5h2IFR18WMFrwCgv/PNAC8FTZCErvc0KHnx0zpC...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.