Initalising Objects in Separate File

This is a discussion on Initalising Objects in Separate File within the C++ Programming forums, part of the General Programming Boards category; Hi everyone http://images.daniweb.com/smilies/sleek/qqb014.gif At the minute I'm working on some stuff learning c++ and was wondering if ayone could offer ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    1

    Question Initalising Objects in Separate File

    Hi everyone http://images.daniweb.com/smilies/sleek/qqb014.gif

    At the minute I'm working on some stuff learning c++ and was wondering if ayone could offer some advice...

    Say I have a pile of objects that need to be created (for example say, a Log object, XML parsers object, and a command line parser object). In my main.cpp file I have a pile of code setting up each of these objects, then I add a pointer to these objects to another list (called object manager) so I can pass this list to other parts of the program and get access to the previous mentioned objects.

    Is there a way of creating say a separate file (say LogInit.cpp, XMLParserInit.cpp) that contains all the initalision stuff, and have these file called or run in main.cpp? So that way a user shouldn't have to modify or change main.cpp for a new object or to change stuff, only edit/make a new *object*Init.cpp file?

    Haven't tried much yet, only messed about with a few idas, such as having a InitObject object that could maybe contain a Init method, then say logInit.cpp extends this InitObject class and overrides the Init method?


    Sorry if this makes no sense, feel free to tell me it's a crazy idea if ya want and of course thanks in advance for any help!

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by KingTravis1986 View Post
    Hi everyone http://images.daniweb.com/smilies/sleek/qqb014.gif

    At the minute I'm working on some stuff learning c++ and was wondering if ayone could offer some advice...

    Say I have a pile of objects that need to be created (for example say, a Log object, XML parsers object, and a command line parser object). In my main.cpp file I have a pile of code setting up each of these objects, then I add a pointer to these objects to another list (called object manager) so I can pass this list to other parts of the program and get access to the previous mentioned objects.

    Is there a way of creating say a separate file (say LogInit.cpp, XMLParserInit.cpp) that contains all the initalision stuff, and have these file called or run in main.cpp? So that way a user shouldn't have to modify or change main.cpp for a new object or to change stuff, only edit/make a new *object*Init.cpp file?

    Haven't tried much yet, only messed about with a few idas, such as having a InitObject object that could maybe contain a Init method, then say logInit.cpp extends this InitObject class and overrides the Init method?


    Sorry if this makes no sense, feel free to tell me it's a crazy idea if ya want and of course thanks in advance for any help!
    Now thats some crossposting ! ( Initalising Objects.. - C++ | DaniWeb )
    Even the smiley link is there. :P
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by KingTravis1986 View Post
    tell me it's a crazy idea
    Sounds like it. I am also pretty sure you are conflating the terms object and class:

    So that way a user shouldn't have to modify or change main.cpp for a new object or to change stuff, only edit/make a new *object*Init.cpp file?

    Haven't tried much yet, only messed about with a few idas, such as having a InitObject object that could maybe contain a Init method, then say logInit.cpp extends this InitObject class and overrides the Init method?
    Honestly, that does not make any sense. An object is not a class, and vice versa.

    Which all implies (no offence) that you are going way beyond your limitations. You should post some code.
    Last edited by MK27; 02-26-2012 at 03:29 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to import DLL function from a separate C file
    By high123_98 in forum C++ Programming
    Replies: 7
    Last Post: 11-12-2011, 10:57 AM
  2. Help with using a Function from a separate file.
    By RelentlessWiz in forum C++ Programming
    Replies: 4
    Last Post: 07-23-2011, 03:33 PM
  3. #define from a separate file
    By Syekiya in forum C Programming
    Replies: 6
    Last Post: 09-19-2010, 03:33 AM
  4. Functions in a separate file
    By Fox101 in forum C Programming
    Replies: 1
    Last Post: 01-29-2008, 01:53 PM
  5. WinProc in separate file
    By ChrisWard1000 in forum Windows Programming
    Replies: 2
    Last Post: 09-10-2004, 07:27 AM

Tags for this Thread


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