473,699 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deriving from std::basic_stre ambuf

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_stre ambuf< MyElem >
{
protected:
int_type overflow( int_type Data = traits_type::eo f() );
};

--= END MyStreamBuffer. h =---

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

template< class MyElem >
int_type MyStreamBuffer: :overflow( int_type Data = traits_type::eo f() )
{
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_stre ambuf that has implementation and the
declaration separated by files.

Thank you!
Jul 22 '05 #1
3 3446
On Sun, 08 Aug 2004 06:16:38 GMT, <ye**@twenty.co m> 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_stre ambuf< MyElem >
{
protected:
int_type overflow( int_type Data = traits_type::eo f() );
};

--= END MyStreamBuffer. h =---

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

template< class MyElem >
int_type MyStreamBuffer: :overflow( int_type Data = traits_type::eo f() )
{
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_stre ambuf 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::eo f()' 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:opsceg92pw 212331@andronic us...
On Sun, 08 Aug 2004 06:16:38 GMT, <ye**@twenty.co m> wrote:
Two things wrong

1) You should not repeat the default argument when you define a function.
Drop ' = traits_type::eo f()' 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.co m> wrote:
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:opsceg92pw 212331@andronic us...
On Sun, 08 Aug 2004 06:16:38 GMT, <ye**@twenty.co m> wrote:
Two things wrong

1) You should not repeat the default argument when you define a
function.
Drop ' = traits_type::eo f()' 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
6199
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 (prerelease) ===========================================
3
3169
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 Reference" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies.
103
48649
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 says about it. What the heck does the binary flag mean? -- If our hypothesis is about anything and not about some one or more particular things, then our deductions constitute mathematics. Thus mathematics may be defined as the subject in...
1
2522
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 somehow my OutBuf::xsputn() is not beeing used. But the orginal basic_streambuf::xsputn() calls my OutBuf::overflow(). http://pastebin.com/483016 - OutBuf.h
6
10032
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 hoped I could solve, and I couldn't. Some code he's using, written in 1999, that compiled fine in 1999, no longer does in 2006 with g++ 4. This little bit of code: SimS::SimS (ostream &s) {
2
2407
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 there's a class called FeaturesFromPng, which contains an instance of Features. The third project contains the main-function in which i want to work with an instance of FeaturesFromPng, but generating the instance produces a LNK2005 error. If i...
2
1757
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, overflow, and underflow. When I see MS VC++6.0 STL code's basic_filebuf implementation, I observed that it is not maintaining any buffering mechanism, instead it is directly handling with the files. Please correct me if I am understanding in a wrong way.
7
3109
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 his input buffer and trys to assign an iterator to a char pointer. .... class winzoostreambuffer : private LoggerConsole, public sts::basic_streambuf<char, std::char_traits<char>> ....
2
2189
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 KhcAnjl/xFAEJb056UdQaCZqPfnGbqA+ =0Y8B -----END PGP SIGNATURE----- -----BEGIN PGP SIGNATURE-----
0
9173
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
9033
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
7748
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
5872
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
4375
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
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.