Thread: Whats wrong with my program?

  1. #1
    Novice Programmer Pyroteh's Avatar
    Join Date
    Jan 2005
    Location
    Alaska
    Posts
    82

    Question Whats wrong with my program?

    Can anyone tell me?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    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 A;
            cout << "end block" >> endl;
        }
        return 0;
    }
    I'm just experimenting....

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    For future reference, it helps to state what errors/problems you are getting.

    Code:
    obj::obj( ) { ... }
    obj::~obj( ) { ... }
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Novice Programmer Pyroteh's Avatar
    Join Date
    Jan 2005
    Location
    Alaska
    Posts
    82
    here are the errors I'm getting


    'obj' : function should return a value; 'void' return type assumed

    '::~obj' : illegal global destructor

    function 'int __cdecl obj(void)' already has a body

    syntax error : missing ';' before identifier 'A'

    'A' : undeclared identifier

    syntax error : missing ';' before identifier 'A'

    binary '>>' : 'class std::basic_ostream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Make the modifications that I posted above in red.

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Novice Programmer Pyroteh's Avatar
    Join Date
    Jan 2005
    Location
    Alaska
    Posts
    82
    sweet thanks!!

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    2
    My first guess it the include piece. It should be #include <iostream.h> instead of plain iostream.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    No it shouldn't. Things like that changed with the latest C++ standard. Do a board search to find out more.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Maze Program - What am I doing wrong?
    By Gipionocheiyort in forum C++ Programming
    Replies: 20
    Last Post: 08-02-2007, 01:31 PM
  2. Replies: 5
    Last Post: 01-13-2007, 02:14 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  4. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 09:57 AM
  5. Whats wrong with my program?
    By Ruflano in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2002, 05:09 PM