Today I accidentally put const
at the beginning of my constructor (copy paste mistake) and it compiled. I've only tried this in Visual Studio 2008 which is pre C++11. Does this syntax have any meaning? Is this Microsoft's early attempts at constexpr
?
class foo
{
public:
const foo(int i){}
};
foo f(1);
Constructors may be declared as inline , explicit , friend , or constexpr . A constructor can initialize an object that has been declared as const , volatile or const volatile . The object becomes const after the constructor completes.
To declare a constant member function, place the const keyword after the closing parenthesis of the argument list. The const keyword is required in both the declaration and the definition.
The const keyword is the variable value which never changes at compile time. In short, the compiler predicts what value is to be stored in the variable itself. Flutter spontaneously gathers variable type information when you confirm and iprocess the same as a const variable.
Dart defines a constructor with the same name as that of the class. A constructor is a function and hence can be parameterized. However, unlike a function, constructors cannot have a return type. If you don't declare a constructor, a default no-argument constructor is provided for you.
Your code is not standard compliant, there is no such thing. However, starting with C++11, you can have constexpr
constructors, so your object is constructed at compile time and can further be used in constexpr
expressions.
Although I am not using it, MSVS is not the best compiler in terms of standard-compliance, at least that's what I realized from various questions on this site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With