473,387 Members | 1,574 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,387 software developers and data experts.

sentry member class

I am reading TC++PL3 and in 21.3.8 it describes the class sentry, which
is member of basic_istream and basic_ostream.

Q1: Should we always use the sentry class when we define new functions
and operators for basic_ostream/basic_istream (ostream/istream)?

Q2: It is mentioned that we can place code "such as throwing exceptions
caused by state changes" in the sentry's destructor. However in 14.4.7
it is mentioned:

"Exiting from a destructor by throwing an exception is also a violation
of the standard library requirements (E2)".

I suppose both sentry's constructor and destructor, are to be provided
by the implementer of the standard library basic_istream and
basic_ostream classes?
Sep 15 '07 #1
1 2034
On Sep 15, 4:50 pm, john <j...@no.spamwrote:
I am reading TC++PL3 and in 21.3.8 it describes the class sentry, which
is member of basic_istream and basic_ostream.
Q1: Should we always use the sentry class when we define new functions
and operators for basic_ostream/basic_istream (ostream/istream)?
It depends. If all your operator does is call existing <</>>
operators, it probably isn't necessary; those operators will
themselves create an instance of the sentry class. But in
general, yes.
Q2: It is mentioned that we can place code "such as throwing exceptions
caused by state changes" in the sentry's destructor.
I suspect that you've misquoted something here. You can't place
anything in sentry's destructor, since it is provided by the
standard library, and you cannot modify it.
However in 14.4.7
it is mentioned:
"Exiting from a destructor by throwing an exception is also a violation
of the standard library requirements (E2)".
I suppose both sentry's constructor and destructor, are to be provided
by the implementer of the standard library basic_istream and
basic_ostream classes?
Exactly.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 15 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jian H. Li | last post by:
Hello, What's the essential differences between the two ways of "class::member" & "object.member"(or object_pointer->member)? class C{ public: void f() {} int i; };
2
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of a Rectangle. If I have a member of type Point...
5
by: snnn | last post by:
#include <iostream> using namespace std; int main(){ const ostream::sentry ok(cout); if(ok) return 0; else return -1; } The codes above can work well under VC++2003,but not gcc!
14
by: Dave Booker | last post by:
It looks like the language is trying to prevent me from doing this sort of thing. Nevertheless, the following compiles, and I'd like to know why it doesn't work the way it should: public class...
7
by: Valeriu Catina | last post by:
Hi, consider the Shape class from the FAQ: class Shape{ public: Shape(); virtual ~Shape(); virtual void draw() = 0;
7
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
1
by: john | last post by:
On Sep 15, 4:50 pm, john <j...@no.spamwrote: To be more precise it is mentioned in TC++PL3,on page 624: "Code that needs to be executed first (the "prefix code") - such as flushing a tied...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.