Thread: Class vector member initilization.

  1. #16
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Segmentation fault (core dumped)
    Oh so it crashes my program?.... no thanks

    edit: Thanks lazer that clears things up. I was confused thinking she was refering to my get function....hence the comment above

    so use the vector.at(index)

    I just tested that and it terminates the program as well. I'd rather just use my internal error check and know the program will continue running and maybe a wall just won't be textured rather than the entire game shuts down over a peice of corrupt data. Is an internal range check really costing me that much in overhead?
    Last edited by Lesshardtofind; 01-02-2013 at 06:32 AM.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Lesshardtofind
    Oh so it crashes my program?.... no thanks
    Refer to my post #14. You failed to catch std::out_of_range. Actually, it would be better to catch std::exception by const reference in your main function (and also have the catch all handler), then log whatever exceptions fall through to that point, possibly displaying an error message of your own choosing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    ok I guess I need to do some lessons on throws and catches then...
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  4. #19
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    BTW, if you have some idea about how large these can get, calling reserve on the vector inside the constructor may be a good idea.

    Also, can you use
    std::vector<std:: pair<IndexType, ImageType>>
    ?
    It would make some stuff simpler and others a little ( like having to put .first , .second everywhere )cumbersome.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by manasij7479
    Also, can you use
    std::vector<std:: pair<IndexType, ImageType>>
    ?
    It would make some stuff simpler and others a little ( like having to put .first , .second everywhere )cumbersome.
    Heh, in that case you might as well define a struct for the pair.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by Elysia View Post
    Show me why you can't simply swallow the exception in a service.
    You need to dream big first of all: plains, trains, automobiles. Device drivers. Things that if they fail, fail spectacularly and the results are very unpleasant.

    Exceptions are sometimes verboten in projects. For bad reasons most of the time, but it's also possible because something needs to be running correctly nearly all of the time and having exception errors is just not good enough. This is because, by the workings of exceptions, the code flow needs to leave the important part to actually handle the exception. So even "swallowing up" is still an interruption.
    Last edited by whiteflags; 01-02-2013 at 06:50 AM.

  7. #22
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    I just ended up using one image to point to the data so that the GLuint could Become a handle for it. Once the texture was generated to the handle I cleared the last Image from memory then added the next. Only needed one Image data type to do all the texture loading. Saved alot of overhead from the method I had started at. Ended up only needing one vector of GLuint.

    I'm going to be honest I have no idea what your example means, but I will look into it.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-18-2012, 11:17 AM
  2. class vector member template
    By Tropod in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2012, 05:28 PM
  3. Replies: 3
    Last Post: 03-21-2008, 12:19 AM
  4. Replies: 2
    Last Post: 11-04-2007, 12:55 PM
  5. Class member variables only readable by member functions?
    By _Elixia_ in forum C++ Programming
    Replies: 4
    Last Post: 10-10-2003, 03:52 PM