a snippet of c++ code, i can't find the error?

Discussion in 'C++' started by entrepreneur, Oct 24, 2006.

  1. entrepreneur

    entrepreneur Guest

    this is the code:
    #include<iostream.h>
    #include<string.h>
    int count=0;
    class obj{
    public :
    obj();
    ~obj();
    };
    obj() {
    ++count;
    cout<<count<<endl;
    }
    ~obj(){
    --count; cout<<count<<endl;
    }
    int main(){
    obj A;

    cout<<"begin block "<<endl;
    obj B;
    cout<<"end block"<<endl;

    return 0;
    }
    where is the error? can someone point it out for me?
    your help will be greatly appreciated.
    best regards.
     
    entrepreneur, Oct 24, 2006
    #1
    1. Advertising

  2. entrepreneur

    heltena Guest

    try this:

    #include<iostream> // changed!
    // changed!

    int count=0;
    class obj{
    public :
    obj();
    ~obj();
    };

    obj::eek:bj() { // changed!
    ++count;
    std::cout<<count<<std::endl; // changed!
    }

    obj::~obj(){ // changed!
    --count; std::cout<<count<<std::endl; // changed!
    }

    int main(){
    obj A;

    std::cout<<"begin block "<<std::endl; // changed!
    obj B;
    std::cout<<"end block"<<std::endl; // changed!

    return 0;
    }

    On Oct 24, 2:37 pm, "entrepreneur" <> wrote:
    > this is the code:
    > #include<iostream.h>
    > #include<string.h>
    > int count=0;
    > class obj{
    > public :
    > obj();
    > ~obj();};obj() {
    > ++count;
    > cout<<count<<endl;}~obj(){
    > --count; cout<<count<<endl;}int main(){
    > obj A;
    >
    > cout<<"begin block "<<endl;
    > obj B;
    > cout<<"end block"<<endl;
    >
    > return 0;}where is the error? can someone point it out for me?
    > your help will be greatly appreciated.
    > best regards.
     
    heltena, Oct 24, 2006
    #2
    1. Advertising

  3. entrepreneur

    VJ Guest

    entrepreneur wrote:
    > this is the code:
    > #include<iostream.h>
    > #include<string.h>
    > int count=0;
    > class obj{
    > public :
    > obj();
    > ~obj();
    > };

    OBJ::eek:bj() {
    > ++count;
    > cout<<count<<endl;
    > }

    OBJ::~obj(){
    > --count; cout<<count<<endl;
    > }
    > int main(){
    > obj A;
    >
    > cout<<"begin block "<<endl;
    > obj B;
    > cout<<"end block"<<endl;
    >
    > return 0;
    > }
    > where is the error? can someone point it out for me?
    > your help will be greatly appreciated.
    > best regards.
    >
     
    VJ, Oct 24, 2006
    #3
  4. entrepreneur

    Martin Steen Guest

    entrepreneur wrote:

    > where is the error? can someone point it out for me?
    > your help will be greatly appreciated.
    > best regards.


    Is this a joke or a test? What makes you think that
    there is an error?

    -Martin
     
    Martin Steen, Oct 24, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Clare Hsiao
    Replies:
    0
    Views:
    348
    Clare Hsiao
    Feb 12, 2004
  2. Johannes Lochmann
    Replies:
    0
    Views:
    381
    Johannes Lochmann
    Aug 18, 2006
  3. Replies:
    19
    Views:
    562
    Alf P. Steinbach
    Jan 30, 2008
  4. Chris Stankevitz
    Replies:
    33
    Views:
    1,485
    Chris Stankevitz
    Nov 19, 2011
  5. Krekna Mektek
    Replies:
    3
    Views:
    113
Loading...

Share This Page