Thread: calling constructor crashes program?

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    calling constructor crashes program?

    This is driving me crazy. I'm making an rpg with an "other people" class. In order to init this class I need data from both the "player" and "map" classes, so I prototyped my constructor like this:
    Code:
    people_t(player_t,map_t);
    This is the way my player constructor works (only it only has one param, map_t) and that works just fine. I figure that this should totally work, but for some reason the program quits on this line:
    Code:
    people_t people(player,map);
    I attached the three offending files, people.h/cpp define the class and Eastman.cpp uses it. Does anybody know what might be causing this?
    Illusion and reality become impartiality and confidence.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    Doesn't your construcor need to have names?

  3. #3
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    The name of a constructor is the name of a class, right? And that's the prototype in the .h, the actual header goes a little somethin' like this:
    Code:
    people_t::people_t(player_t player, map_t map)
    is that it? (thx for reply)
    Illusion and reality become impartiality and confidence.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by ichijoji
    The name of a constructor is the name of a class, right? And that's the prototype in the .h, the actual header goes a little somethin' like this:
    Code:
    people_t::people_t(player_t player, map_t map)
    is that it? (thx for reply)
    Yep, you're correct. The constructor is the name of the class itself.

    That's quite the constructor you've got there. Rather large. The easy way to find the cause of your problem will be simply to start removing unneeded lines.

    For example: Variable initialization which doesn't use a function call, is rarely, if ever, cause of a crash. Thus, you can rule them out.

    Second, you can narrow down your problem a great deal by simply adding debugging lines. Something as simple as:
    Code:
    	w = player.wis();
    	h = player.his();
    	cout << "w is " << w << ", h is " << h;
    Naturally you'll want to use something else for output if you're in some graphics mode. Consider outputting this to a file and flushing the output instead.

    No, it doesn't directly answer your question as to what is the cause, but yes, it should help narrow it a bit.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    Thx for the reply. I actually have a little function I developed for debugging (short version:):
    Code:
    void check() {
        static int count = 1;
        allegro_message("Checkpoint #%d",count++);
    }
    With calls to this right before the line in Eastman.cpp declaring an instance of the people class and the first line of the people initializer, I only got one checkpoint before the program shut down. Puzzling, no?
    Illusion and reality become impartiality and confidence.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    Well, since most usual crashes all caused by incorrectly indexing into an array of some sort, I would check into that. Sorry but that's all I can tell ya.

  7. #7
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    You need to declare a default initializer. (ie: people_t(); )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  2. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  3. calling programs from a c++ program
    By md4u in forum C++ Programming
    Replies: 0
    Last Post: 05-04-2003, 07:39 AM
  4. calling c++ program from a webpage
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-04-2001, 09:41 AM