Results 1 to 6 of 6

Thread: Boost Tutorial and Help

  1. #1
    Join Date
    Jun 2006
    Location
    Near Toronto Ontario
    Beans
    604
    Distro
    Ubuntu 9.10 Karmic Koala

    Boost Tutorial and Help

    Hi all, i am looking to learn some of the boost library so i can do better parsing of my arguments to main. Currently i use cstring but i was told not to on this forum. Anyways i have heard god thing about it but i do not know exactly where to start. The tutorials on the boost site are good but a little scattered and i am confused on what i am exactly looking for to do the job. Could somebody link me to a good tutorial and maybe give me some example code. Thanks
    Visit my Blog at http://rekahsoft.org

  2. #2
    Join Date
    Mar 2005
    Location
    Dunedin, NZ
    Beans
    559
    Distro
    Kubuntu 7.10 Gutsy Gibbon

    Re: Boost Tutorial and Help

    The link you need to follow is this one: http://boost.org/doc/html/program_options/tutorial.html

    If you have any particular questions, feel free to ping me on freenode.
    ACCU - for programmers who care

  3. #3
    Join Date
    Jun 2006
    Location
    Near Toronto Ontario
    Beans
    604
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Boost Tutorial and Help

    ok...i will work on it tomorrow after school thanks
    Visit my Blog at http://rekahsoft.org

  4. #4
    Join Date
    Jun 2006
    Location
    Near Toronto Ontario
    Beans
    604
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Boost Tutorial and Help

    ok..i have been reading the tutorial and i have some questions. How does the following code work:
    Code:
    po::options_description desc("Allowed Options");
    desc.add_options()
    		("about", "Test made by Collin Doering")
    		("help", "produce help message")
    ;
    specificaly how is it possable to have
    Code:
    ("about", "Test made by Collin Doering")
    ("help", "produce help message")
    after the call to add_options()??? also how do i go about compiling a file that contains includes to the boost library? I tried
    Code:
    g++ srcfile.cc `pkg-config --libs --cflags boost-1.33`
    but no success
    Visit my Blog at http://rekahsoft.org

  5. #5
    Join Date
    Mar 2005
    Location
    Dunedin, NZ
    Beans
    559
    Distro
    Kubuntu 7.10 Gutsy Gibbon

    Re: Boost Tutorial and Help

    The syntax for program options takes advantage of the wonders of C++ operator overloading and returning references.

    Without actually reading the code, they are probably doing something like:
    Code:
    ...
    some_helper add_options()
    {
       return some_helper(*this);
    }
    ...
    
    class some_helper
    {
       public:
          some_helper(options_description& opts);
          some_helper& operator()(std::string const& name, std::string const& text)
          {
             // save the options
             opts.add_option(name, text);
             return *this;
           }
    };
    So something is overloading the function call operator to do stuff, and returning a reference to something (perhaps itself) that also overrides the function call operator.

    'Aint C++ grand?

    As far as compiling goes, you need to install the packages: libboost-dev and libboost-program-options-dev.

    Then on the command line I think you just need to is to specify the libboost_program_options.so on the command line for g++.
    ACCU - for programmers who care

  6. #6
    Join Date
    Jun 2006
    Location
    Near Toronto Ontario
    Beans
    604
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Boost Tutorial and Help

    ok..i will give that a try...i forgot about the fact that the () operator can be overloaded...that causes some really wierd behavior...neat...i am still getting used to C++...thanks...i will report back with any problems &| issues
    Visit my Blog at http://rekahsoft.org

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •