invisible.hippo
Arch-Supremacy Member
- Joined
- Nov 8, 2008
- Messages
- 17,902
- Reaction score
- 315
Hi, i am confused between two different example of inheritance and copy constructor
In the first example
Baz( std::string foo ) : foo( foo ) { }
If i am not wrong, the above means that an argument is passed into foo funcion. Then the foo function will store this value. Next the Baz function contain 1 private member call string foo. String foo will take in 1 argument. This argument is known as foo and the value of this foo is from the function know as foo.
Why is the example shown below giving a different explanation
In the above example shouldnt it be like
Lastly am i correct for the concept of inheritence
class ten
{
protected:
int a,b,c
public:
void ten();
};
class one
{
private:
int a,b,c
public:
void one();
};
void one:
ne(int 1,int 2,int 3) : ten(int 10,int20,int30)
{
1 = 30;
2 = 20;
3 = 30;
a=1;
b=2;
c=3;
}
In the first example
Code:
class Baz
{
public:
Baz( std::string foo ) : foo( foo ) { }
private:
std::string foo;
};
is roughly equivalent to
class Baz
{
public:
Baz( std::string foo )[QUOTE][/QUOTE]
{
this->foo = foo;
}
private:
std::string foo;
};
Baz( std::string foo ) : foo( foo ) { }
If i am not wrong, the above means that an argument is passed into foo funcion. Then the foo function will store this value. Next the Baz function contain 1 private member call string foo. String foo will take in 1 argument. This argument is known as foo and the value of this foo is from the function know as foo.
Why is the example shown below giving a different explanation
Code:
Foo::Foo( const Foo& f ) : x( f.x ), str( strdup( f.str ) ){}
In this particular case, the above is equivalent to
Foo::Foo( const Foo& f )
{
x = f.x;
str = strdup( f.str );
}
In the above example shouldnt it be like
Code:
Foo::Foo( const Foo& f )
{
f = f.x;
}
class ten
{
protected:
int a,b,c
public:
void ten();
};
class one
{
private:
int a,b,c
public:
void one();
};
void one:
ne(int 1,int 2,int 3) : ten(int 10,int20,int30){
1 = 30;
2 = 20;
3 = 30;
a=1;
b=2;
c=3;
}