Afficher un message
Vieux 06/06/2008, 19h55   #8
utab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Static variable & static method

On 6 jun, 12:20, Stefan Istrate <stefan.istr...@gmail.com> wrote:
> Hello,
> I have the following code and I still don't know why it prints "10 10"
> instead of "5 10".
>
> #include <iostream>
> using namespace std;
>
> class A {
> static int i;
> public:
> static int get_i() {
> return i;
> }
> static int dbl() {
> i = i * 2;
> return i;
> }
>
> };
>
> int A::i = 5;
>
> int main() {
> cout << A::get_i() << " " << A::dbl() << endl;
> return 0;
>
> }
>
> Can anyone me understand this?
> Thank you,
> Stefan Istrate


Others have clarified that but there is one more subtle point to
state, maybe. The function calls can have some side effects, such as
throwing exceptions and so on. Therefore, it is best to keep the
output operations seperate from the function calls. Some experinced
will comment on this maybe...
  Réponse avec citation
 
Page generated in 0,04618 seconds with 9 queries