C++ 0x – Implicit Callable Functions(ICF)

In the new proposed standard for C++, for the functions, which are taking empty number of arguments, now it can be called without paranthesis . It gives a look of property of classes, offer by languages like C#. See the example below

int GetBkColor () implicit { return 0; }Â
// The above function can be called asÂ
int nDrawColor = GetBkColor;
// No paranthesis required
Â
Implicit function calls can be used with classes for getting and setting properties.
Â
class Square {
public:

double & side() implicit { return side_; }
// …
private:
double side_; // length in cm
};
Â
Square s;
s.side = 5.0; // set value
cin >> s.side; // set value
cout<< s.side; // get value
Â

In the above example making the function non-const will enable itself to get and set the values. 

Checkout the ICF Proposal

C++ 0x – Auto Types

The automatic type declarations are very rarely or seldom used in C++. Now it really stands it’s meaning to make use of Automatic types.

auto f = GetValue();

In the above code, f will be of type on what Getvalue() function returns. This feature is already there other programming languages like VB. Auto type is really useful in Generic programming (using templates).

There’s another type declaration feature will be added to the core language. The new language will include decltype keyword for declaring a variable having same type of another (existing) without knowing the other variable type. This is really handy in context with auto type.

 int a = 10;
decltype(a) b;
decltype(int) a; // Error and redundant

Now the new variable “b” will be of type “a”. Check out the proposal for decltype for more information

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.