answersLogoWhite

0

Can constructor be declared as constant in c plus plus?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

No. Constructors initialise objects and, by definition, must be able to modify the member variables. Uninitialised members are a disaster waiting to happen even without a constructor declared const! Thankfully, the compiler won't permit a const constructor.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can constructor be declared as constant in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you write own constructor in c plus plus?

Yes.


True or False A C plus plus class constructor cannot return a function value?

True - A C++ constructor cannot return a value.


What is the difference between implicit and explicit call of constructor in c plus plus?

An implicit constructor call will always call the default constructor, whereas explicit constructor calls allow to chose the best constructor and passing of arguments into the constructor.


What is the constant in C programming language?

Anything declared as a constant.


What are the two types of constant in c plus plus?

Constant data and constant functions.


What does a constant do in c plus plus?

A constant is a variable that does not change. The correct term is constant variable.


What is friend constructor?

A friend constructor is a constructor that is declared a friend of another class and that grants that constructor private access to the class in which it is declared a friend. Example: class Y { friend char* X::foo (int); // friend function friend X::X (char); // constructors can be friends friend X::~X(); // destructors can be friends }; For more information, see '11.3 Friends' in the current ISO C++ Standard.


What is the difference between constructor and friend function in c plus plus?

A constructor is a method that fires when the object is instantiated. A friend function is a function that has special access to the object. They are two different types of things, and cannot be further differenced.


How can a constructor be invoked at the time of inheritance in C Plus Plus?

It cannot. Inheritance is a compile-time operation. Constructors are invoked at runtime at the point of instantiation.


How do you invoke the constructor function in c plus plus?

There is no such thing as a constructor function in C++ (constructors have no return value, not even void, and cannot be called like regular functions). Constructors are invoked rather than called directly, either by declaring a static variable of the class type, or via the C++ new operator.


What is a constant object in c plus plus?

A constant object is one that, once initialized, never changes value.


Is there any friend constructor in c?

C is not an object-oriented programming language so there is no friend keyword let alone friend constructors. In C++, however, constructors can be declared friends. Consider the following code where the class Y default constructor has private access to X::foo() because the Y::Y() constructor is explicitly declared a friend of class X. Note that Y must be defined before X can be defined, thus X must be forward declared. #include<iostream> class X; // fwd declaration class Y { public: Y() { X x; x.foo(); } // X::foo is private, but Y::Y() is a friend. }; class X { friend Y::Y(); // friend constructor private: void foo() {} };