473,395 Members | 1,941 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,395 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 2036
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.