Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How do you initialize a class member,
class x {
const int i;
};

Answers were Sorted based on User's Feedback



How do you initialize a class member, class x { const int i; };..

Answer / pappu

class abc
{
int a=4,b=3;
virtual mul(int int)=0;
}

Is This Answer Correct ?    10 Yes 1 No

How do you initialize a class member, class x { const int i; };..

Answer / guest

x()
{i=10;
}

Is This Answer Correct ?    3 Yes 1 No

How do you initialize a class member, class x { const int i; };..

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

How do you initialize a class member, class x { const int i; };..

Answer / pc1989

x variable();

Is This Answer Correct ?    2 Yes 1 No

How do you initialize a class member, class x { const int i; };..

Answer / harminder

It can be done in the intialization list of the constructor

x():i=10
{
}

Is This Answer Correct ?    3 Yes 2 No

How do you initialize a class member, class x { const int i; };..

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

How do you initialize a class member, class x { const int i; };..

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

How do you initialize a class member, class x { const int i; };..

Answer / anandam niranjan

i think it's not possible

Is This Answer Correct ?    5 Yes 6 No

Post New Answer

More C++ General Interview Questions

What can c++ be used for?

0 Answers  


If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?

0 Answers  


What is the difference between map and hashmap in c++?

0 Answers  


What is compilation?

1 Answers   Datamatics, TCS,


Difference between declaration and definition of a variable.

0 Answers  


Write a Program to find the largest of 4 no using macros.

0 Answers  


Mention the ways in which parameterized can be invoked. Give an example of each.

0 Answers  


throw Can constructors exceptions?

1 Answers  


How many namespaces are there in c++?

0 Answers  


What are the two types of comments, and how do they differ?

0 Answers  


Write any small program that will compile in "C" but not in "C++"

10 Answers   Honeywell,


structure contains int, char, float how it behaves for big endian and little endian?

1 Answers   BITS,


Categories