PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Variable life cycle
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Variable life cycle

Réponse
 
LinkBack Outils de la discussion
Vieux 26/12/2007, 06h26   #1
George2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Variable life cycle

Hello everyone,


In the sample, I am wondering what is the life cycle of variable b_?
Could we access variable b_ in catch block?

I have this confusion is because,

1. I think b_ is member variable, and we should be able to access it
anywhere in the class itself, so we can access b_ in catch block;

2. I think b_ is declared and initialized in try {} block, and catch
exceeds the {} of try, so we can not access b_ in catch block.

Which option is correct?

http://www.gotw.ca/gotw/066.htm

Code:
class C:
{
B b_;

C::C()
try
: b_( /*...*/ )
{
}
catch( ... )
{
// can we access _b here?
}

};

thanks in advance,
George
  Réponse avec citation
Vieux 26/12/2007, 07h09   #2
Bo Persson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Variable life cycle

George2 wrote:
:: Hello everyone,
::
::
:: In the sample, I am wondering what is the life cycle of variable
:: b_? Could we access variable b_ in catch block?
::
:: I have this confusion is because,
::
:: 1. I think b_ is member variable, and we should be able to access
:: it anywhere in the class itself, so we can access b_ in catch
:: block;
::
:: 2. I think b_ is declared and initialized in try {} block, and
:: catch exceeds the {} of try, so we can not access b_ in catch
:: block.
::
:: Which option is correct?
::
:: http://www.gotw.ca/gotw/066.htm
::
::
Code:
:: class C:
:: {
::  B b_;
::
::  C::C()
::  try
::    : b_( /*...*/ )
::  {
::  }
::  catch( ... )
::  {
::    // can we access _b here?
::  }
::
:: };
::
::

It think Herb explains it very well in the article - if C's
constructor fails, there is no C object. What are you to access?

This is a very unusual construct, that has hardly any use at all. In
fact, most compilers hasn't bothered to implement it.


Bo Persson





  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h21.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09278 seconds with 10 queries