Does 'auto' type assignments of a pointer in c++11 require '*'?

does definition
does in a sentence
does thesaurus
does and do
does not
what does mean
meaning of does in hindi

Given my variable being a pointer, if I assign it to a variable of "auto" type, do I specify the "*" ?

std::vector<MyClass> *getVector(); //returns populated vector

std::vector<MyClass> *myvector = getVector();  //assume has n items in it
auto newvar1 = myvector;

// vs:
auto *newvar2 = myvector;

//goal is to behave like this assignment:
std::vector<MyClass> *newvar3 = getVector();

I'm a bit confused on how this auto works in c++11 (this is a new feature to c++11, right?)

Update: I revised the above to better clarify how my vector is really populated in a function, and I'm just trying to assign the returned pointer to a variable. Sorry for the confusion

auto newvar1 = myvector;

// vs:
auto *newvar2 = myvector;

Both of these are the same and will declare a pointer to std::vector<MyClass> (pointing to random location, since myvector is uninitialized in your example and likely contains garbage). So basically you can use any one of them. I would prefer auto var = getVector(), but you may go for auto* var = getVector() if you think it stresses the intent (that var is a pointer) better.

I must say I never dreamt of similar uncertainity using auto. I thought people would just use auto and not think about it, which is correct 99 % of the time - the need to decorate auto with something only comes with references and cv-qualifiers.

However, there is slight difference between the two when modifies slightly:

auto newvar1 = myvector, newvar2 = something;

In this case, newvar2 will be a pointer (and something must be too).

auto *newvar1 = myvector, newvar2 = something;

Here, newvar2 is the pointee type, eg. std::vector<MyClass>, and the initializer must be adequate.

In general, if the initializer is not a braced initializer list, the compiler processes auto like this:

  1. It produces an artificial function template declaration with one argument of the exact form of the declarator, with auto replaced by the template parameter. So for auto* x = ..., it uses

    template <class T> void foo(T*);
  2. It tries to resolve the call foo(initializer), and looks what gets deduced for T. This gets substituted back in place of auto.

  3. If there are more declarators in a single declarations, this is done for all of them. The deduced T must be the same for all of them...

Does, Rhymes: -ʌz. VerbEdit. does. Third-person singular simple present indicative form of do. Alternative formsEdit · -'s (after interrogative pronouns). Etymology 2​Edit. Define does. does synonyms, does pronunciation, does translation, English dictionary definition of does. v. Does - definition of does by The Free Dictionary

There is a, perhaps subtle, difference between auto and auto* when it comes to constness.

int i;
const auto* p = &i;

is equivalent to

int i;
const int* p = &i;


int i;
const auto p = &i;

is equivalent to

int i;
int* const p = &i;

This has the following effect:

void test(int a) {
    const auto* p1 = &a;

    *p1 = 7;               // Error
    p1 = nullptr;          // OK

    const auto p2 = &a;

    *p2 = 7;               // OK
    p2 = nullptr;          // Error

does, does definition: Does references the performance or achievements of another. (​verb) An example of does is telling a friend that your husband is in marketing,  does definition: Does references the performance or achievements of another. (verb) An example of does is telling a friend that your husband is in marketing, "He does marketing."

auto newvar1 = *myvector;

This is probably what you want, which creates a copy of the actual vector. If you want to have a reference instead write auto& newvar1 = *myvector; or to create another pointer to the same vector use auto newvar1 = myvector;. The difference to your other attempt auto *newvar1 = myvector; is that the latter once forces myvector to be of pointer type, so the following code fails:

std::vector<int> v1;
auto* v2 = v1; // error: unable to deduce ‘auto*’ from ‘v1’

Does dictionary definition, Define DOES and get synonyms. What is DOES? DOES meaning, pronunciation and more by Macmillan Dictionary. does definition: 1. he/she/it form of do 2. he/she/it form of do 3. present simple of do, used with he/she/it. Learn more.

DOES definition and synonyms, (Washington, DC) – The District of Columbia Department of Employment Services (DOES) reported today 29. APR. Washington Metro's Unemployment at 3.4  DOES en español will allow Spanish speaking customers to access information about the programs and services offered by the Department of Employment Services in Spanish. DOES en español permitirá a los clientes de habla hispana acceder a información sobre los programas y servicios ofrecidos por el Departamento de Servicios de Empleo en español.

| does, The Department of Employment Services is receiving a higher than normal call volume and encourages claimants to apply for unemployment compensation  Do and does are used when we want to ask yes/no questions. We use do or does depending on the subject. Below are two sentences with two different subjects, she and you. Does she like sport?

Unemployment Compensation, does meaning: 1. he/she/it form of do 2. he/she/it form of do 3. present simple of do, used with he/she/it. Learn more. Office Hours Monday to Friday, 8:30 am to 5 pm Connect With Us 4058 Minnesota Avenue, NE, Washington, DC 20019 Phone: (202) 724-7000 Fax: (202) 673-6993

  • The goal doesn't make sense; that assignment will not compile in C++.
  • auto_ptr is deprecated now...
  • I should have clarified that I'm creating (on heap) and populating a vector in a function, then returning a pointer to that vector, and want to create a variable to store the pointer. I've edited my question to elaborate.
  • I revised my question to clarify that I'm looking to assign a pointer to a populated vector to this variable. Can you check to see if your answer still applies that the two syntaxes are the same? Thanks!
  • @ildjarn empirical evidence appears to disagree with you. I get the same results on Clang 3.4 and gcc 4.8.3. Furthermore, it obeys template type deduction: if a primary template deduces T=int*, then a specialization for pointers would deduce T=int. For auto* p = &i; the deduced int type is then 'enhanced' with the pointer declarator part of auto*, producing the same type as in auto p = &i.
  • @boycy : You're correct, I don't know what I was thinking (references and cv-qualifiers I guess). Thanks for speaking up, downvote removed. :-]
  • const auto p = &i is equivalent to int* const, not const int* const. In your example it is ok to do *p2 = 7;.
  • @danadam, you are right. I've updated the example.
  • So use const auto * const p for total constness?
  • Any advice on how to avoid not copying (note: my question has been revised to clarify what I'm looking to do -- sorry for not being clear before)
  • As told, use auto& newvar1 = *myvector; This does not copy.
  • OP didn't "want" anything.