How do you initialize a class member,
class x {
const int i;
};
Answers were Sorted based on User's Feedback
Answer / pappu
class abc
{
int a=4,b=3;
virtual mul(int int)=0;
}
| Is This Answer Correct ? | 10 Yes | 1 No |
Answer / santosh patil
class members can be initialized directly like
class x{const int i=10;}
but its structures members tat cant be initialized lik above
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / harminder
It can be done in the intialization list of the constructor
x():i=10
{
}
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / gayatri
using constructor we can initialize a class member in public
part of class.
class x
{
private: int i;
public: x()
{
i = 10;
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / jp
const data members must be initialized using Initializer List. In the following example, “t” is a const data member of Test class and is initialized using Initializer List.
#include<iostream>
using namespace std;
class Test {
const int t;
public:
Test(int t):t(t) {} //Initializer list must be used
int getT() { return t; }
};
int main() {
Test t1(10);
cout<<t1.getT();
return 0;
}
/* OUTPUT:
10
*/
| Is This Answer Correct ? | 0 Yes | 0 No |
What is a multiset c++?
Write a function that swaps the values of two integers, using int* as the argument type?
Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.
A milk carton can hold 3.78 litres of milk. Each morning, a dairy farm ships cartons of milk to a local grocery store. The cost of producing one litre of milk is $0.38, and the profit of each carton of milk is $0.27. Write a C++ program that prompts the user to enter the total amount of milk produced in the morning. Then display the number of milk cartons needed to hold milk, the cost of producing milk, and the profit for producing milk.
What can c++ be used for?
Explain friend class?
How can you tell what shell you are running on unix system?
What is the use of ‘using’ declaration?
If all is successful, what should main return a) 0 b) 1 c) void
How would you stop a class from class from being derived or inherited?The constructer should not be Private,as object instantiation should be allowed.
List the issue that the auto_ptr object handles?
What is a c++ class?