Like Tree5Likes

Class vector member initilization.

This is a discussion on Class vector member initilization. within the C++ Programming forums, part of the General Programming Boards category; Segmentation fault (core dumped) Oh so it crashes my program?.... no thanks edit: Thanks lazer that clears things up. I ...

  1. #16
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    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.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,118
    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.
    Lesshardtofind and Elysia like this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    407
    ok I guess I need to do some lessons on throws and catches then...

  4. #19
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,500
    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.
    Lesshardtofind likes this.
    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 !



  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,118
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,751
    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
    407
    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.

Page 2 of 2 FirstFirst 12
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, 06:28 PM
  3. Replies: 3
    Last Post: 03-21-2008, 01: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, 04:52 PM

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