Thread: Starting to get aggrivated with classes....

  1. #16
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    It shouldn't. You forgot to #include <cstdio>.
    It does, and no, I didn't forget.
    Last edited by 7stud; 05-31-2003 at 08:21 PM.

  2. #17
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    getchar( ) is defined in <cstdio>, not <iostream>.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #18
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    Ok, i think i did this right, but it won't compile. Ill post the code and the compiler errors.

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <fstream.h>
    
    class workingclass
    {
     public:
     workingclass();
     ~workingclass();
    };
    
    workingclass()
    {
    cout<<"stuff";
    }
    ~workingclass()
    {
    }
    
    
    int main(int argc, char *argv[])
    {
     
     
     
      system("PAUSE");	
      return 0;
    }

    And the errors i get....

    Code:
    12 C:\Documents and Settings\User\Desktop\main.cpp
    parse error before `('
    
    17 C:\Documents and Settings\User\Desktop\main.cpp
    destructors must be member functions
    
     C:\Documents and Settings\User\Desktop\Makefile.win
    [Build Error]  [main.o] Error 1
    ~matt~

  4. #19
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Almost there.

    1)Don't use header files with .h extensions. Use the equivalent header names found here:

    http://www.cplusplus.com/doc/ansi/hfiles.html

    2)Add a using declaration after your includes, like

    using namespace std;

    3)For short functions you should just define them inside the class. If you do define a function outside the class, it must be qualified with the class name, so that the compiler knows what class the definition belongs to, like this:
    Code:
    workingclass::workingclass()
    {
       cout<<"stuff";
    }
    Just add "workingclass::" in front of any function you define outside of your class. Also, if you had a function with a return type of int, this is what the format would look if you defined it outside the class:
    Code:
    int workingclass::my_function()
    {
        .....
        return 50;
    }
    The return type goes all the way to the left.

    4)Unless you're going to be using arguments entered on the command line(which I assume you aren't) use the following format for main():
    Code:
    int main()
    {
       ....
       ....
       return 0;
    }
    It's much easier to type.
    Last edited by 7stud; 06-01-2003 at 04:07 AM.

  5. #20
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I have to use .h, thats why i do that. Someone esle already told me that above.
    You have to? Who says so? You are already using one non-h header (<iostream>), so you can use all others too.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #21
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    When i delete off the .h, i get compiler errors. Does it really make a difference anyways?

    Also, what excactly does "using namespace std;" or whatever it was, do?
    ~matt~

  7. #22
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    Ok, update, scratch that compiler error stuff with the .h. I didnt know that it was written different in C++.
    ~matt~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. Just starting to learn C++ Question about classes
    By uraliss in forum C++ Programming
    Replies: 3
    Last Post: 04-12-2006, 03:31 AM
  4. Problems with classes... just starting out w/ them.
    By criticalerror in forum C++ Programming
    Replies: 25
    Last Post: 03-05-2004, 12:19 PM
  5. Starting with classes: Your opinion
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-30-2002, 06:22 PM