How can a class constructor initilize a member variable or a class array? dose it have to do with the 'this' operator?
struct default{
default();
float num;
}def[4];
default::default() {
?????
}
How can a class constructor initilize a member variable or a class array? dose it have to do with the 'this' operator?
struct default{
default();
float num;
}def[4];
default::default() {
?????
}
You could give the struct constructor a default argument -
You'll also want to change the name of your struct, as default is a revserved keyword.Code:struct defaulty{ defaulty(float n =10); float num; }def[4]; defaulty::defaulty(float n){ num=n; }
zen
Yes but how do i initilize the members of each object. Do i have to make implicit calls.
default::default() {
def[0].num = 0;
def[1].num = 0;
def[2].num = 0;
def[3].num = 0;
}
in zens example its already done.
struct defaulty{
defaulty(float n =10);
float num;
}def[4];
the def[4] defines an array of 4 defaulty structs. for each struct the constructor will have been called with the default value so therefore it is initialised.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi