Thread: Something wrong in initialization?

  1. #1
    Shadow12345
    Guest

    Something wrong in initialization?

    Here is my source code
    #include <IOSTREAM.H>
    #include <string.h>

    class universal
    {
    public:
    char *getname() {return itsname;}
    void setname(char *name) { strncpy (itsname, name, 50 ); }
    protected:
    char itsname[50];
    };

    class godublic universal
    {
    public:
    void createland(int land) {
    cout << "\nCreating land";
    godland = land;}

    int getland() { return godland;}

    void createpeople(int people) {
    cout << "\nCreating people";
    godspeople = people;}

    int getpeople() { return godspeople;}

    protected:
    int godland;
    int godspeople;

    };

    int main()
    {

    god thor = new god;

    return 0;
    }

    I think the error lies in the line
    god thor = new god;
    but I am not sure why that is not correct someone help me plz

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    "new" allocates a pointer to an object. So off-hand I'd say you need:
    Code:
    god* thor=new god;
    Other than that what's the problem? You main() doesn't do anything but allocate memory for the god object (which you need to free with delete god) and then end (return(0)).

    Oh, and use code tags. It makes things easier to read. And also, click on "Disable Smilies in This Post" too (notice the god class).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM