Questions tagged [auto]

The `auto` keyword was repurposed in C++11 for a deduced type. When used to replace a type name in an initialized variable declaration, the variable is given the same type as the initializer. When used as a return type, the return type is specified as a trailing return type, or deduced from the return-expression.

Consider the following code:

bool Function()
{
    return true;
}

bool result = Function();

The return type of Function is unambiguously known at compile time, so the variable declaration can be replaced with:

auto result = Function();

The type of result will thus be deduced. The auto keyword becomes very useful, when type name is long:

for (std::vector<MyNamespace::MyType>::const_iterator iter = v.cbegin(); iter != v.cend(); iter++)

C++11 allows shorter declaration:

for (auto iter = v.cbegin(); iter != v.cend(); iter++)

It is worth noting that the keyword auto changed meaning with advent of C++11 and it is almost always used in this new context.

1055 questions
-4
votes
2 answers

Why do i keep getting break error? I have the same problem with continue and pass

from webbot import Browser import time import pyautogui from pyautogui import * web = Browser() a == True web.go_to('http://au.yahoo.com//') web.scrolly(100) if a == True: try: web.click('Skip for now') …
-4
votes
5 answers

Is it possible to declare auto variables with an if?

My Code is below. struct conv{ struct des { des(int a) {} des(int a, int b) {} des(int a, int b, int c) {} }; }; int main(int argc, const char * argv[]) { int a = 1; int b = 1; int c = 1; if (a > 1) { auto…
冯剑龙
  • 498
  • 7
  • 17
-4
votes
2 answers

Access auto declared array

auto messwerte2 = { 3.5, 7.3, 4.9, 8.3, 4.4, 5.3, 3.8, 7.5 }; Which possibilities exist to access a single value explicitly of this array-like looking structure which as I was informed is actually a std::initializer_list ?
baxbear
  • 679
  • 2
  • 6
  • 24
-4
votes
4 answers

Keyword "auto" near critical points

Possible Duplicate: How much is too much with C++0x auto keyword I find using "auto" near critical points maybe cause some problems. This is the example code: #include #include #include using std::cout; using…
UniversE
  • 535
  • 2
  • 5
  • 24
-6
votes
1 answer

Would an break-less switch/case be feasible?

Would the suggestion to have a syntax for a switch that does not need breaks all the time feasible? My suggestion would be to insert auto both before switch and each case: auto switch(expr) { auto case 1: statement; statement; auto case 2:…
towi
  • 20,210
  • 25
  • 94
  • 167
-24
votes
4 answers

Why not drop the "auto" keyword?

Now that the auto keyword was introduced in c++ 11, I think that we should be able to drop specifying auto and simply initialize variables as v = 20. Since C++ is able to deduce the type of a variable on its own, why not drop the auto keyword all…
nagavamsikrishna
  • 809
  • 1
  • 10
  • 21
1 2 3
70
71