struct name
{
int &fea_id;
Rwgvector(rfval) &rfval;
name(int &f, Rwgvector(rfval) &r):fea_id(f),rfval(r) {};
};
Line 3 will not compile - you can't use a reference like that.
Line 4 will not compile - you can't use a reference like that, and I don't know what Rwgvector(rfval) is.
Line 5 will not compile - I don't know what Rwgvector(rfval) is, and there is an extra semicolon.
hey Disch, in line 5 what is the function of the colon there and can you explain a little about the part after the colon,don't know what it is and what its called.
The colon marks the start of the initializer list. The comma separated list that follows is -- you guessed it! -- the initializer list.
Basically, you can specify arguments for constructors of member and parent classes here, and also initialize intrinsic member variables using the 'constructor like' syntax.
It's better to initialize variables here than to assign them in the body of the constructor if possible, because it's more efficient (at least with custom types?). Using an initializer list means your member variables are constructed straight away with their intended values. Assigning custom type variables means they are default constructed and then initialized.
@Disch I'm not sure if I've quite explained that right - correct me if I'm wrong :)
class Parent
{
public:
Parent(int v); // a constructor that takes an int as a param
};
// say we have a child class, and the child wants to initialize its parent with that above construtor:
class Child : public Parent
{
private:
string s;
int i;
public:
Child() // the child constructor
: Parent(5) // call the parent's constructor
, s("example") // call s's constructor
, i(15) // call i's ctor
{ }
};