vividexstance's Profile User Rating: *****

Reputation: 656 Enlightened
Active Posts:
2,251 (1.68 per day)
31-December 10
Profile Views:
Last Active:
User is offline Aug 30 2014 06:12 AM

Previous Fields

Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
Expert In:

Latest Visitors

Icon   vividexstance has not set their status

Posts I've Made

  1. In Topic: Need help overloading comparison operators

    Posted 29 Aug 2014

    Because you don't modify the objects in the comparison operators, you should be passing them as const references.
  2. In Topic: Vector and copy constructor

    Posted 27 Aug 2014

    View Postdarek9576, on 27 August 2014 - 11:57 AM, said:

    My questions are:

    1) When the vector holds custom objects, we need to provide copy consttuctor if the class' member variables point to the heap, however when they dont, we dont need to provide the copy constructor?
    2)When the vector goes out of scope, its destructor runs, will it call a destructor for each object that it holds, so that a proper clean up takes place?


    Question 1: There are two main ways to perform a copy, a shallow copy (which the default constructor does), and a deep copy (which should happen when you're dealing with pointers). You have to implement the copy and assignment operator to perform the deep copy. I typically implement a helper function to perform the copy and then just call the helper function in the copy constructor and assignment operator.

    Question 2: No, the vector doesn't clean up any dynamically allocated storage that it may be holding. This is up to the programmer. Just remember, whenever you use the new operator, there should always be a reciprocal delete operator call somewhere else in the program (whenever the storage isn't used anymore).

    Note: With C++11, there is such a thing as "move" semantics which would help in this situation, but I sense that you're a beginner so maybe you should wait and learn some more until trying to understand move semantics.

    I forgot to mention about "smart" pointers that the C++ standard library provides that allow you to dynamically allocate storage on the heap and not have to worry about cleaning the storage up later. Here's two links to some good C++ reference sites:
    And here's a specific link to a "smart" pointer class:
    That's just one type of smart pointer, there are a few more.

    I would highly recommend bookmarking those two sites. If you intend to really learn C++, you will use them heavily.
  3. In Topic: unordered_map is behaving differently from expected.

    Posted 25 Aug 2014

    If you just want to know if a key is in the map but don't need an iterator to it, then why not use the unordered_map::count() member function?
  4. In Topic: Split string by string.

    Posted 24 Aug 2014

    Have a look at this page, specifically, the find_*() family of functions. I would think, using find_first_of() would work. Then you just need to use a loop until you don't find the string you're looking for. Once you know the position of the string you're looking for, you can use the string::substr() function to retrieve it.

    To check if the find_*() functions didn't find a match, you compare the result of the function call to std::string::npos which stands for "no position". If it equals npos, then the string wasn't found.
  5. In Topic: Can anyone help me optimize my function definition

    Posted 24 Aug 2014

    It's already been said, but I'll repeat it. Design your functions so that they do ONE thing and ONE thing only. If you start writing a function and it begins to get large, you should consider splitting it up into separate functions.

    Another good tip is too be on the look out for code repetition. When you start seeing code that is being repeated in your code with only slight changes to it, then you should consider "abstracting" that code into it's own function. Whatever changes slightly in the repeated code should be turned into arguments/parameters to the function.

    Doing this and using good naming techniques for functions can really cut down on your program sizes, and help tremendously when reading the code. Also, it will help any maintenance that might be done on the program at some later date.

My Information

Member Title:
D.I.C Lover
Age Unknown
Birthday Unknown

Contact Information

Click here to e-mail me


Page 1 of 1
  1. Photo

    orihotomihsah Icon

    09 Sep 2013 - 09:45
Page 1 of 1