Const
A shortened version of the words "constant" and/or "constantly."
"You know, now that I actually pay attention to myself, I find myself const correcting his grammar. Kind of annoying, no?"
"I like how they're const blasting the music in the car, even though the speakers are going to blast."
"I like how they're const blasting the music in the car, even though the speakers are going to blast."
const
const is a qualifer that, when applied, will make sure that const variables are read-only. Such attempt to modify a const variable directly will result in a compiler error.
Additionally, const variables mut be initialized upon declaration.
Another use of const is to make functions const. Const functions promises to NOT modify member variables of its' class. The const keyword is placed after the identifier, but before the function body.
Additionally, const variables mut be initialized upon declaration.
Another use of const is to make functions const. Const functions promises to NOT modify member variables of its' class. The const keyword is placed after the identifier, but before the function body.
const int c{5}; // uniform initilization
// now c is const, any attempt to modify it results in an error
c = 6; // error, c is const
int d;
d = c; // fine, we're not modifing c
// another example:
class A
{
int a;
public:
A(): a(5) {}
void incrementA() { ++a; }
void incrementA2() const { ++a; } // error, incrementA2 is const, and will not modify a
};
// now c is const, any attempt to modify it results in an error
c = 6; // error, c is const
int d;
d = c; // fine, we're not modifing c
// another example:
class A
{
int a;
public:
A(): a(5) {}
void incrementA() { ++a; }
void incrementA2() const { ++a; } // error, incrementA2 is const, and will not modify a
};
consted
drunk mans version of boosted
background> one night of drunkenness, one mobile phone with predicta-text turned off, one drunk man trying to input boosted
background> one night of drunkenness, one mobile phone with predicta-text turned off, one drunk man trying to input boosted
see boosted
T* const this
The hidden *this pointer that's present in every member function of a class (at least, in C++).
class Something
{
int a,b;
public:
Something(int a, int b): this->a(a), this->b(b)
{}
void doSomething() {} // is translated into "void doSomething(Something* const this) {}"
// The T in "T* const this" is replaced with the class type
friend void doSomething2() {} // is not translated, as it is NOT a member function
};
void doSomething2() {}
{
int a,b;
public:
Something(int a, int b): this->a(a), this->b(b)
{}
void doSomething() {} // is translated into "void doSomething(Something* const this) {}"
// The T in "T* const this" is replaced with the class type
friend void doSomething2() {} // is not translated, as it is NOT a member function
};
void doSomething2() {}