answersLogoWhite

0

You can. Every constructor has an initialise segment immediately before the body.

class myClass

{

public:

myClass(): // note the colon: initialisation segment follows...

myInt( 0 ),

myChar( '0' )

{

myPtr = new char; // you can also initialise members in the body.

// if you have a lot of members and several constructors, create

// a private init() method to maintain a consistent initialisation.

}

private:

char myChar;

int myInt;

char * myPtr

};

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

Can an abstract method be declared static in java?

No you cant, any compiler I've ever used wont allow this. It would not make any sense to do this anyway. because the JVM directly accesses ur top class without instantiating it. Though for accessing the instance data members, the class must need to be instantiated.


What is true about true about abstract data type Object of an abstract class type cant be created. We can derive classes from these abstract classes Object of an abstract class t?

True - an instance of an abstract class cannot be created. False - derive (subclass) from a class, not the object (the instance).


What is the extension of a java byte code file?

.class is the extension of a java byte code file.


Can you use extern and static together?

Storage classes are used to indicate duration and scope of a variable or identifier. Duration indicates the life span of a variable. Scope indicates the visibility of the variable. The static storage class is used to declare an identifier that is a local variable either to a function or a file and that exists and retains its value after control passes from where it was declared. This storage class has a duration that is permanent. A variable declared of this class retains its value from one call of the function to the next. The scope is local. A variable is known only by the function it is declared within or if declared globally in a file, it is known or seen only by the functions within that file. This storage class guarantees that declaration of the variable also initializes the variable to zero or all bits off. The extern storage class is used to declare a global variable that will be known to the functions in a file and capable of being known to all functions in a program. This storage class has a duration that is permanent. Any variable of this class retains its value until changed by another assignment. The scope is global. A variable can be known or seen by all functions within a program.


How does friend operator function differ from member operator function?

In C++, we know that private members cannot be accessed from the outside class.That is a non-member function cannot have an access to the private data of a class.However there could be a situation where we would like two classes to share a particular function.For example consider a case where two classes, manager and scientist have been defined.We would like to use a function income_ tax () to operate on the objects of both these classes.In such situation, C++ allows the common function to be made friendly with both the classes. Such a function needs not be member of any these classes.To make outside function friendly to a class, we have to simply declare this function as a friend of a class as shown below:Class ABC{………..Public:……..……..Friend void xyz (void); //declaration};When the function is logically coupled with the class (like your maze connectedness example)When the function needs to access private or protected members, it's better to make it a member than a friend. when it's a generic function that can be templatized to naturally work on other classes (look at the header for good example) .

Related Questions

How do w can you get no class in adventure quest worlds?

you could get this class during a event. the event is over now so u cant get it but there is a glitch. equip a members class and when ur membership runs out you will be wearing no class


How do you ditch lessons?

you run away from class as soon you get within two meters of the door, screaming "IM DITCHING CLASS IM DITCHING CLASS HAHA YOU CANT CATH ME" if that doesn't work (it never did for me :P) then you're out of luck. ask some high schoolers :Dyou run away from class as soon you get within two meters of the door, screaming "IM DITCHING CLASS IM DITCHING CLASS HAHA YOU CANT CATH ME" if that doesn't work (it never did for me :P) then you're out of luck. ask some high schoolers :D


Can an abstract method be declared static in java?

No you cant, any compiler I've ever used wont allow this. It would not make any sense to do this anyway. because the JVM directly accesses ur top class without instantiating it. Though for accessing the instance data members, the class must need to be instantiated.


You can pay for school but you cant buy class?

Class what? Units? Supplies?


How do you become wooz ban members?

you cant


Why cant you log in on 99chats?

to be active members


Where a non-members get herbs on runescape?

you cant


Why has the family failed in socializing its members?

theory? in what culture? from what perspective? usa.... rampant poverty, 40% uninsured, shrinking middle class, violent lower class, psychological disorders. homocidal manics are born that way. cant do anything about them. science says that is so.


How do you get lancer class in tales of the world?

You cant.


How do give other members passes on Howrse?

you cant


How do non members on clubpenguin get member stuff?

they cant


How do you get important questions of 7 class?

u cant