C++ keywords

Hi,
I just want to know what these kewords mean and many ways to use them.

auto, ref, const(used for methods--functions i classes)

Thanks in advance,
Aceix.
There is no such keyword ref in C++.
To my knowledge, there is no ref keyword in C++.
In the D language ref is short for reference, and used for function parameters it's equivalent to a non-const reference declaration in C++.

Example:
1
2
3
void f(ref int i); // D

void f(int &i); // C++ 


auto comes from good old C.
Up until C++11 it used to describe automatic variables. The complement of auto is static.

Now, all local variables are automatic by default, which is why the keyword was very seldom used -- which is why in C++11 its meaning changed to automatic type inference. If the compiler can infer the type of a variable from its initialization, you can use auto instead of writing the type yourself.

Example:
1
2
3
4
5
6
7
8
std::vector<int> vi;

std::vector<int>::const_iterator it1 = vi.begin(); // C++98
auto it2 = vi.cbegin(); // C++11

std::map<char, int> mci;

for (const auto &p: mci); // p is std::pair<char, int> 


const... you use it to mark your variables constant. You also use it to mark your references constant. Finally, you use it to signify that a member function doesn't change the member data.

http://www.parashift.com/c++-faq/const-correctness.html
Thanks to you all

Aceix.
closed account (Dy7SLyTq)
actually...
http://msdn.microsoft.com/en-us/library/7b8kbexc(v=vs.80).aspx
Thank you all but I still don't get the use of ref.

Aceix.
As I already said there is no such keyword ref in C++.
@vlad from moscow
Ok, but I see it in some C++ codes. Also check the link DTSCode provided.

Aceix.
I can repeat the third time: there is no such keyword as ref in C++ This means that using such identifier is implementation defined. In the C++ Standard there is defined function ref(). But names of functions have nothing common with keywords except operator functions new and delete.
Last edited on
catfish4 wrote:
The complement of auto is static.


Huh?
I guess that OP refers to this:

http://msdn.microsoft.com/en-us/library/windows/apps/hh699870.aspx

it's a microsoft language extension
@ Disch: why not make a meaningful rebuttal instead of just "huh", huh?
It wasn't a rebuttal, it was a show of confusion.

But you're right I could have been clearer. How about this:


"What do you mean by that?"
@ Disch: I meant that since automatic variables are not the same as static variables -- they are two complementary kinds of local variables.
Oh okay. I get what you mean.
Topic archived. No new replies allowed.