Thread: a few questions about C++

  1. #1
    Registered User
    Join Date
    May 2008

    a few questions about C++

    What is the reference ( & ) operator for?
    What does it mean to use the keyword "operator" like so
    MyPointer* operator=( &MyPointer );
    I've also read that vectors, are just bigger arrays, in the form of a container?

    If I have more questions, I'll update the thread.
    Last edited by bobbelPoP; 06-29-2008 at 07:52 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    & is an address-of operator. By default it returns the address of an object (it has nothing to do with references in that usage).

    For operators like +, =, ++, <<, etc, you can overload their meaning when applied to non built-in types. There is an error in your example because the & should go after the class name instead of before it to indicate that it is a reference.

    A vector is not a bigger array. A vector is a dynamic array. It can grow as you add items and it cleans up after itself. This makes it a better choice than regular dynamic arrays in C++ (arrays created with new[] and destroyed with delete[]).

  3. #3
    Registered User
    Join Date
    Jun 2008
    whats the difference between a map and a vector then?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    whats the difference between a map and a vector then?
    A map is an associative container that maps keys to values. A vector is a sequential container that stores objects contiguously.
    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

  5. #5
    Registered User
    Join Date
    Jan 2005
    There are many differences, too many to list. First, they are implemented quite differently.

    From a semantic point of view the vector is sort of like a specific kind of map. It maps consecutive integral indexes from 0 - n to the value stored in the vector. A map can have any type as the key (as long as it has certain traits), it doesn't have to be an integer, it doesn't have to be consecutive, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM