Skipping a header file until int/class/whatever exists?

This is a discussion on Skipping a header file until int/class/whatever exists? within the C++ Programming forums, part of the General Programming Boards category; Okay, so I'm making a game with an engine called Irrlicht, however I have trouble doing some stuff because of ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    14

    Skipping a header file until int/class/whatever exists?

    Okay, so I'm making a game with an engine called Irrlicht, however I have trouble doing some stuff because of the order of how the process goes. I want my source codes clean and easy on the eye.

    Is there any way to skip a header or .cpp file using any kind of method, (#pragma, loops, etc.) so I can skip certain files until I have a specific pointer/class/int/whatever declared and used? Will I have to be creative? Or is there a pre-made way already, I'm really starting to grasp more sophisticated subjects on C++ thanks to note taking, books, and online resources.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Example?

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    14
    Well, take this for example:

    I start with a pointer called "device", and the Irrlicht engine makes it to where the "device" pointer is declared in main(). Now my problem is functions and objects, I can't put an object up at the top before main() because #include can't be used within main() or below naturally, because of this my code will eventually become a complete mess with the prototypes at the top, functions at the bottom, and objects who-knows-where. This leads to a compile error. I'd have to put EVERYTHING in main.cpp, which I REALLY don't want to do.

    I'm using Visual C++ 2008 Express by the way, sorry, this is as best as I can explain it.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Sorry, what you're saying just doesn't make a whole lot of sense. Perhaps a small, concrete (and compilable) example of what you're trying to do would help?

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by GlitchGuy2 View Post
    Now my problem is functions and objects, I can't put an object up at the top before main() because #include can't be used within main() or below naturally
    This makes negative amounts of sense. If you want to put something before main, then a prohibition on putting things after main could not possibly stand in your way (of putting something before main).

    You are not expected to put everything in main.cpp. You are expected, if you have more than one .cpp file, to put them all in the same project.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by GlitchGuy2 View Post
    I start with a pointer called "device", and the Irrlicht engine makes it to where the "device" pointer is declared in main(). Now my problem is functions and objects, I can't put an object up at the top before main()
    Of course you can! What would make you say otherwise?
    because #include can't be used within main() or below naturally,
    Actually in certain cases they can, not that you'd necessarily want to. Why would you suggest that such a thing might be helpful in your case?
    because of this my code will eventually become a complete mess with the prototypes at the top, functions at the bottom
    You don't have to have the function prototypes at the top. You can declare the entire function prior to main instead and then no function prototype is required.
    , and objects who-knows-where. This leads to a compile error. I'd have to put EVERYTHING in main.cpp, which I REALLY don't want to do.
    No, you really don't want to do that! Sounds like you don't understand how to lay out a C++ program across multiple source files.
    You show what you think the problem is, with actual code, and we'll show you how it's supposed to be done.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21