Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Synthesized and non-inherited class members

Reply
Thread Tools

Synthesized and non-inherited class members

 
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      11-12-2006
Could you tell me how many class members the C++ language synthesizes
for a class type? Which members in a class aren't derived from parent
classes?

I have read the book The C++ Programming Language, but there isn't a
detail and complete description on all the class members, aren't they
important to class composing? Could you explain the special class
behavior in detail? Thank you very much.

 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      11-12-2006

lovecreatesbea...@gmail.com wrote:
> Could you tell me how many class members the C++ language synthesizes
> for a class type? Which members in a class aren't derived from parent
> classes?
>
> I have read the book The C++ Programming Language, but there isn't a
> detail and complete description on all the class members, aren't they
> important to class composing? Could you explain the special class
> behavior in detail? Thank you very much.


Please read the following:
http://www.parashift.com/c++-faq-lite/how-to-post.html

 
Reply With Quote
 
 
 
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      11-13-2006

"Salt_Peter 写道:"
> lovecreatesbea...@gmail.com wrote:
> > Could you tell me how many class members the C++ language synthesizes
> > for a class type? Which members in a class aren't derived from parent
> > classes?
> >
> > I have read the book The C++ Programming Language, but there isn't a
> > detail and complete description on all the class members, aren't they
> > important to class composing? Could you explain the special class
> > behavior in detail? Thank you very much.

>
> Please read the following:
> http://www.parashift.com/c++-faq-lite/how-to-post.html


Thank you.

Do you mean it is a homework problem or it is a FAQ problem? Why do you
direct me to that link? I ever read Scott Meyers popular book Effective
C++, in one print of its second edition, he said that a pair of &
operators are synthesized by the language.

I also think this question is important and not difficult to me. If you
experts know the answer exactly, I would like to ask for your help
sincerely.

 
Reply With Quote
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      11-13-2006

"lovecreatesbea...@gmail.com 写道:
"
> "Salt_Peter 写道:"
> > lovecreatesbea...@gmail.com wrote:
> > > Could you tell me how many class members the C++ language synthesizes
> > > for a class type? Which members in a class aren't derived from parent
> > > classes?
> > >
> > > I have read the book The C++ Programming Language, but there isn't a
> > > detail and complete description on all the class members, aren't they
> > > important to class composing? Could you explain the special class
> > > behavior in detail? Thank you very much.

> >
> > Please read the following:
> > http://www.parashift.com/c++-faq-lite/how-to-post.html

>
> Thank you.
>
> Do you mean it is a homework problem or it is a FAQ problem? Why do you
> direct me to that link? I ever read Scott Meyers popular book Effective
> C++, in one print of its second edition, he said that a pair of &
> operators are synthesized by the language.
>
> I also think this question is important and not difficult to me.


Sorry for the typo above, I mean it's important and difficult to me,
and come here asking for your help. Please help me.

 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      11-13-2006

lovecreatesbea...@gmail.com wrote:
> "Salt_Peter 写道:"
> > lovecreatesbea...@gmail.com wrote:
> > > Could you tell me how many class members the C++ language synthesizes
> > > for a class type? Which members in a class aren't derived from parent
> > > classes?
> > >
> > > I have read the book The C++ Programming Language, but there isn't a
> > > detail and complete description on all the class members, aren't they
> > > important to class composing? Could you explain the special class
> > > behavior in detail? Thank you very much.

> >
> > Please read the following:
> > http://www.parashift.com/c++-faq-lite/how-to-post.html

>
> Thank you.
>
> Do you mean it is a homework problem or it is a FAQ problem? Why do you
> direct me to that link? I ever read Scott Meyers popular book Effective
> C++, in one print of its second edition, he said that a pair of &
> operators are synthesized by the language.
>
> I also think this question is important and not difficult to me. If you
> experts know the answer exactly, I would like to ask for your help
> sincerely.


Those aren't & operators. You are referring to a copy constructor and
an assignment operator.
Scott Meyers' book explains that quite well.
The following are generated for you if a class is declared and defined
as empty and _if_ these are needed:

class A { };

// def ctor
A::A() { }
// copy ctor
A::A(const& copy) { }
// destructor
A::~A() { }
// assignment operator
A& Aoperator=(const A& rhv) { }

What happens if you add members depends on whether the members are
primitive types or other user-types. If primitives, these are
allocated, not initialized and bit-copied, if user-types, their
corresponding def ctors/d~tors/copies are invoked.
It would be nice if you stated which case you wanted to investigate.
You need to specify which situation you'ld like considered because a
book can be written on that subject alone. A simple example would do
with members, perhaps.

Otherwise, i'll end up rambling in all directions getting into endless
arguements with a few hundred people about what exactly happens at
exactly what point in time. I can seriously think of over 10 different
configurations off the top of my head involving everything from
primitive members, abstract bases, pure virtual diamonds, members of
members, virtual d~tors, private derived classes, containers, embedded
classes, and the list goes on and on.

 
Reply With Quote
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      11-13-2006

Salt_Peter wrote:
> lovecreatesbea...@gmail.com wrote:
> > "Salt_Peter 写道:"
> > > lovecreatesbea...@gmail.com wrote:
> > > > Could you tell me how many class members the C++ language synthesizes
> > > > for a class type? Which members in a class aren't derived from parent
> > > > classes?
> > > >
> > > > I have read the book The C++ Programming Language, but there isn't a
> > > > detail and complete description on all the class members, aren't they
> > > > important to class composing? Could you explain the special class
> > > > behavior in detail? Thank you very much.
> > >
> > > Please read the following:
> > > http://www.parashift.com/c++-faq-lite/how-to-post.html

> >
> > Thank you.
> >
> > Do you mean it is a homework problem or it is a FAQ problem? Why do you
> > direct me to that link? I ever read Scott Meyers popular book Effective
> > C++, in one print of its second edition, he said that a pair of &
> > operators are synthesized by the language.
> >
> > I also think this question is important and not difficult to me. If you
> > experts know the answer exactly, I would like to ask for your help
> > sincerely.

>
> Those aren't & operators. You are referring to a copy constructor and
> an assignment operator.
> Scott Meyers' book explains that quite well.
> The following are generated for you if a class is declared and defined
> as empty and _if_ these are needed:
>
> class A { };
>
> // def ctor
> A::A() { }
> // copy ctor
> A::A(const& copy) { }
> // destructor
> A::~A() { }
> // assignment operator
> A& Aoperator=(const A& rhv) { }
>
> What happens if you add members depends on whether the members are
> primitive types or other user-types. If primitives, these are
> allocated, not initialized and bit-copied, if user-types, their
> corresponding def ctors/d~tors/copies are invoked.
> It would be nice if you stated which case you wanted to investigate.
> You need to specify which situation you'ld like considered because a
> book can be written on that subject alone. A simple example would do
> with members, perhaps.
>
> Otherwise, i'll end up rambling in all directions getting into endless
> arguements with a few hundred people about what exactly happens at
> exactly what point in time. I can seriously think of over 10 different
> configurations off the top of my head involving everything from
> primitive members, abstract bases, pure virtual diamonds, members of
> members, virtual d~tors, private derived classes, containers, embedded
> classes, and the list goes on and on.


Hello peter, thank you very much for the reply.

The author called it operator &. If you have the corresponding print of
his book. He stated the mistake in errata <url:
http://www.aristeia.com/BookErrata/ec++2e-errata_frames.html>. I will
quote the errata of the description on synthesized operator& for
further discussion.

In the following errata, Mr. Meyers mentioned two more glossary:

1. "built-in address-of operator" and
2. "global operator& function".

Is there the third name 3. "class defined operator"?

What do the built-in, global things do to a class. Can they be data
members or member functions? How do they affect the other members are
not built-in and global in a class?

I still want to know which members will (or have the chance to) be
provided automatically for a class? Which members can not be inherited
from the parent classes? Could you master help me?

Thank you.

--quote---
http://www.aristeia.com/BookErrata/e...ta_frames.html

! 2/10/00 ic 212 A class declaring no operator& function(s)
9/10/01
cxh 213 does NOT have them implicitly declared. Rather,
245 compilers use the built-in address-of operator
246 whenever "&" is applied to an object of that
type. This behavior, in turn, is technically
not an application of a global operator&
function. Rather, it is a use of a built-in
operator.
I eliminated mention of operator& as an
automatically generated function and adjusted the
index to eliminate entries for the removed
material.
--quoting ends---

 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      11-13-2006

lovecreatesbea...@gmail.com wrote:
> Salt_Peter wrote:
> > lovecreatesbea...@gmail.com wrote:
> > > "Salt_Peter 写道:"
> > > > lovecreatesbea...@gmail.com wrote:
> > > > > Could you tell me how many class members the C++ language synthesizes
> > > > > for a class type? Which members in a class aren't derived from parent
> > > > > classes?
> > > > >
> > > > > I have read the book The C++ Programming Language, but there isn't a
> > > > > detail and complete description on all the class members, aren't they
> > > > > important to class composing? Could you explain the special class
> > > > > behavior in detail? Thank you very much.
> > > >
> > > > Please read the following:
> > > > http://www.parashift.com/c++-faq-lite/how-to-post.html
> > >
> > > Thank you.
> > >
> > > Do you mean it is a homework problem or it is a FAQ problem? Why do you
> > > direct me to that link? I ever read Scott Meyers popular book Effective
> > > C++, in one print of its second edition, he said that a pair of &
> > > operators are synthesized by the language.
> > >
> > > I also think this question is important and not difficult to me. If you
> > > experts know the answer exactly, I would like to ask for your help
> > > sincerely.

> >
> > Those aren't & operators. You are referring to a copy constructor and
> > an assignment operator.
> > Scott Meyers' book explains that quite well.
> > The following are generated for you if a class is declared and defined
> > as empty and _if_ these are needed:
> >
> > class A { };
> >
> > // def ctor
> > A::A() { }
> > // copy ctor
> > A::A(const& copy) { }
> > // destructor
> > A::~A() { }
> > // assignment operator
> > A& Aoperator=(const A& rhv) { }
> >
> > What happens if you add members depends on whether the members are
> > primitive types or other user-types. If primitives, these are
> > allocated, not initialized and bit-copied, if user-types, their
> > corresponding def ctors/d~tors/copies are invoked.
> > It would be nice if you stated which case you wanted to investigate.
> > You need to specify which situation you'ld like considered because a
> > book can be written on that subject alone. A simple example would do
> > with members, perhaps.
> >
> > Otherwise, i'll end up rambling in all directions getting into endless
> > arguements with a few hundred people about what exactly happens at
> > exactly what point in time. I can seriously think of over 10 different
> > configurations off the top of my head involving everything from
> > primitive members, abstract bases, pure virtual diamonds, members of
> > members, virtual d~tors, private derived classes, containers, embedded
> > classes, and the list goes on and on.

>
> Hello peter, thank you very much for the reply.
>
> The author called it operator &. If you have the corresponding print of
> his book. He stated the mistake in errata <url:
> http://www.aristeia.com/BookErrata/ec++2e-errata_frames.html>. I will
> quote the errata of the description on synthesized operator& for
> further discussion.
>
> In the following errata, Mr. Meyers mentioned two more glossary:
>
> 1. "built-in address-of operator" and
> 2. "global operator& function".


These are free compiler operators that are provided automatically. They
are not synthesized.
Adress_of returns the variable's address (not the class).

>
> Is there the third name 3. "class defined operator"?


No, there is no op* synthesized except for pointers and references.
The op* is only predefined for primitive numerics where its a
mutiplication.

>
> What do the built-in, global things do to a class. Can they be data
> members or member functions? How do they affect the other members are
> not built-in and global in a class?


The built-ins are provided by the compiler to support the language.
There is nothing magic about how they work either.

class A { };
int main()
{
A a; // a variable
A* p_a; // a pointer to nothing
p_a = &a; // a pointer to the a variable (&a is address_of a)
A& r_a(a); // a reference to to a (r_a is a reference to a)
}

>
> I still want to know which members will (or have the chance to) be
> provided automatically for a class? Which members can not be inherited
> from the parent classes? Could you master help me?


i'm no master.
All virtual member functions are inherited by a Child class. Of course,
that doesn't inlude constructors and destructors nor any operator.
Which makes perfect sense since these are specialized for the Parent
class.
Look at it this way, any "function" that generates / initializes an
object of type Parent can't be overloaded or overridden in its
derivatives. The Child class can't overide a ctor, for example.

Why don't you simply investigate the issue:

#include <iostream>

class A
{
public:
A() { std::cerr << "A()\n"; }
virtual ~A() { std::cerr << "~A()\n"; }
A(const A& copy) { std::cerr << "A(...) copy\n"; }
A& operator=(const A& rhv)
{
std::cerr << "A op=\n";
if(&rhv == this) return *this;
// assign members
return *this;
}
};

class Child : public A
{
};

int main()
{
Child child; // ctor
Child another = child; // copy
child = another; // assignment

Child* p_child = &child; // pointer to child
std::cout << "p_child = " << p_child << std::endl;
}

/*
A()
A(...) copy
A op=
p_child = 0x7fffc20ce6e0
~A()
~A()
*/

 
Reply With Quote
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      11-15-2006

Salt_Peter wrote:
> lovecreatesbea...@gmail.com wrote:

<snip>
> > Hello peter, thank you very much for the reply.
> >
> > The author called it operator &. If you have the corresponding print of
> > his book. He stated the mistake in errata <url:
> > http://www.aristeia.com/BookErrata/ec++2e-errata_frames.html>. I will
> > quote the errata of the description on synthesized operator& for
> > further discussion.
> >
> > In the following errata, Mr. Meyers mentioned two more glossary:
> >
> > 1. "built-in address-of operator" and
> > 2. "global operator& function".

>
> These are free compiler operators that are provided automatically. They
> are not synthesized.
> Adress_of returns the variable's address (not the class).
>
> > Is there the third name 3. "class defined operator"?

>
> No, there is no op* synthesized except for pointers and references.
> The op* is only predefined for primitive numerics where its a
> mutiplication.
>>
> > What do the built-in, global things do to a class. Can they be data
> > members or member functions? How do they affect the other members are
> > not built-in and global in a class?

>
> The built-ins are provided by the compiler to support the language.
> There is nothing magic about how they work either.


Thank you again, Peter.

I understand that, for a user-defined class, operators like operator+,
operator-, operator*, operator/ should be overridden to make the class
do plus, minus, multiple and division respectively. (and only
assignment operator is the exception, right?)

you mean there are no built-in (or global) operators provided for a
user-defined class, do I understand you correctly? I can't distinguish
synthesized, predefined or automatically provided members or behavior.

What are are the differences between built-in and global things on a
user-defined class?

When a programmer defines a class, are there some built-in (or global)
operators or functions be added to the class automatically or
synthesized by the language.

> class A { };
> int main()
> {
> A a; // a variable
> A* p_a; // a pointer to nothing
> p_a = &a; // a pointer to the a variable (&a is address_of a)
> A& r_a(a); // a reference to to a (r_a is a reference to a)
> }
>
> >
> > I still want to know which members will (or have the chance to) be
> > provided automatically for a class? Which members can not be inherited
> > from the parent classes? Could you master help me?

>
> i'm no master.
> All virtual member functions are inherited by a Child class. Of course,
> that doesn't inlude constructors and destructors nor any operator.
> Which makes perfect sense since these are specialized for the Parent
> class.
> Look at it this way, any "function" that generates / initializes an
> object of type Parent can't be overloaded or overridden in its
> derivatives. The Child class can't overide a ctor, for example.


Are there only these four members:

default constructor,
copy constructor,
assignment operator,
destructor

will not be inherited from parent classes?

As they will be provided (synthesized or predefined) for the child
classes by the language.

(But how what about the others, how many in total members will be
provided automatically? Which are those?

And which can not be inherited? I ever wrote some example code, but
still can not get a complete and detail list of these special
functions. Thank you.)

> Why don't you simply investigate the issue:
>
> #include <iostream>
>
> class A
> {
> public:
> A() { std::cerr << "A()\n"; }
> virtual ~A() { std::cerr << "~A()\n"; }
> A(const A& copy) { std::cerr << "A(...) copy\n"; }
> A& operator=(const A& rhv)
> {
> std::cerr << "A op=\n";
> if(&rhv == this) return *this;
> // assign members
> return *this;
> }
> };
>
> class Child : public A
> {
> };
>
> int main()
> {
> Child child; // ctor
> Child another = child; // copy
> child = another; // assignment
>
> Child* p_child = &child; // pointer to child
> std::cout << "p_child = " << p_child << std::endl;
> }
>
> /*
> A()
> A(...) copy
> A op=
> p_child = 0x7fffc20ce6e0
> ~A()
> ~A()
> */


 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      11-15-2006

lovecreatesbea...@gmail.com wrote:
> Salt_Peter wrote:
> > lovecreatesbea...@gmail.com wrote:

> <snip>
> > > Hello peter, thank you very much for the reply.
> > >
> > > The author called it operator &. If you have the corresponding print of
> > > his book. He stated the mistake in errata <url:
> > > http://www.aristeia.com/BookErrata/ec++2e-errata_frames.html>. I will
> > > quote the errata of the description on synthesized operator& for
> > > further discussion.
> > >
> > > In the following errata, Mr. Meyers mentioned two more glossary:
> > >
> > > 1. "built-in address-of operator" and
> > > 2. "global operator& function".

> >
> > These are free compiler operators that are provided automatically. They
> > are not synthesized.
> > Adress_of returns the variable's address (not the class).
> >
> > > Is there the third name 3. "class defined operator"?

> >
> > No, there is no op* synthesized except for pointers and references.
> > The op* is only predefined for primitive numerics where its a
> > mutiplication.
> >>
> > > What do the built-in, global things do to a class. Can they be data
> > > members or member functions? How do they affect the other members are
> > > not built-in and global in a class?

> >
> > The built-ins are provided by the compiler to support the language.
> > There is nothing magic about how they work either.

>
> Thank you again, Peter.
>
> I understand that, for a user-defined class, operators like operator+,
> operator-, operator*, operator/ should be overridden to make the class
> do plus, minus, multiple and division respectively. (and only
> assignment operator is the exception, right?)


Yes

>
> you mean there are no built-in (or global) operators provided for a
> user-defined class, do I understand you correctly? I can't distinguish
> synthesized, predefined or automatically provided members or behavior.


Yes, except for address_of and reference operator, as noted by the
author.
Type t;
Type& ref = t; // reference
Type* p = &t; // address_of

>
> What are are the differences between built-in and global things on a
> user-defined class?


Built-in means provided by the compiler. global means globally
accessible.

>
> When a programmer defines a class, are there some built-in (or global)
> operators or functions be added to the class automatically or
> synthesized by the language.


Yes, we've discussed them all, ctor, copy, d~tor and op== are
automatically generated for you. The address_of and reference are
builtin. What you need to know is what happens when you start providing
you own ctors.

>
> > class A { };
> > int main()
> > {
> > A a; // a variable
> > A* p_a; // a pointer to nothing
> > p_a = &a; // a pointer to the a variable (&a is address_of a)
> > A& r_a(a); // a reference to to a (r_a is a reference to a)
> > }
> >
> > >
> > > I still want to know which members will (or have the chance to) be
> > > provided automatically for a class? Which members can not be inherited
> > > from the parent classes? Could you master help me?

> >
> > i'm no master.
> > All virtual member functions are inherited by a Child class. Of course,
> > that doesn't inlude constructors and destructors nor any operator.
> > Which makes perfect sense since these are specialized for the Parent
> > class.
> > Look at it this way, any "function" that generates / initializes an
> > object of type Parent can't be overloaded or overridden in its
> > derivatives. The Child class can't overide a ctor, for example.

>
> Are there only these four members:
>
> default constructor,
> copy constructor,
> assignment operator,
> destructor
>
> will not be inherited from parent classes?


None are "inherited". The parent class can only use them. In some
cases, the destructor is declared as virtual to support polymorphism,
in that case its the virtuality thats inherited. The Child class needs
its own ctors, d~tor and op=.

>
> As they will be provided (synthesized or predefined) for the child
> classes by the language.


That doesn't change the fact that the Child class needs its own. When
the Child type is used to create an object, the compiler needs a base
class ctor to complete the creation of the object (2 ctors are
invoked).

>
> (But how what about the others, how many in total members will be
> provided automatically? Which are those?


That has already been discussed.
Look at it this way, if you write a class without definitions, isn't
the compiler still able to generate, copy, destroy and assign the
object? How does it do that?

class A { };

int main()
{
A a; // ctor
A another(a); // copy ctor
a = another; // assignment op
std::cout << "&a = " << &a << std::endl; // address_of
A& ref = another; // reference
std::cout << "&ref = " << &ref << std::endl;
// a = a + another; // fails, why?
}

>
> And which can not be inherited? I ever wrote some example code, but
> still can not get a complete and detail list of these special
> functions. Thank you.)


Thats a deep issue. What is inherited is any public or protected
function that isn't a ctor, d~tor or assignment. Why don't you code
these? Write 2 classes with std::cerr outputs in their functions and
watch what happens. You should leave inheritance out of the picture
until you understand how classes work.

 
Reply With Quote
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      11-16-2006

Salt_Peter wrote:
> lovecreatesbea...@gmail.com wrote:
> > Salt_Peter wrote:
> > > lovecreatesbea...@gmail.com wrote:

> > <snip>
> > > > Hello peter, thank you very much for the reply.
> > > >
> > > > The author called it operator &. If you have the corresponding print of
> > > > his book. He stated the mistake in errata <url:
> > > > http://www.aristeia.com/BookErrata/ec++2e-errata_frames.html>. I will
> > > > quote the errata of the description on synthesized operator& for
> > > > further discussion.
> > > >
> > > > In the following errata, Mr. Meyers mentioned two more glossary:
> > > >
> > > > 1. "built-in address-of operator" and
> > > > 2. "global operator& function".
> > >
> > > These are free compiler operators that are provided automatically. They
> > > are not synthesized.
> > > Adress_of returns the variable's address (not the class).
> > >
> > > > Is there the third name 3. "class defined operator"?
> > >
> > > No, there is no op* synthesized except for pointers and references.
> > > The op* is only predefined for primitive numerics where its a
> > > mutiplication.
> > >>
> > > > What do the built-in, global things do to a class. Can they be data
> > > > members or member functions? How do they affect the other members are
> > > > not built-in and global in a class?
> > >
> > > The built-ins are provided by the compiler to support the language.
> > > There is nothing magic about how they work either.

> >
> > Thank you again, Peter.
> >
> > I understand that, for a user-defined class, operators like operator+,
> > operator-, operator*, operator/ should be overridden to make the class
> > do plus, minus, multiple and division respectively. (and only
> > assignment operator is the exception, right?)

>
> Yes
>
> >
> > you mean there are no built-in (or global) operators provided for a
> > user-defined class, do I understand you correctly? I can't distinguish
> > synthesized, predefined or automatically provided members or behavior.

>
> Yes, except for address_of and reference operator, as noted by the
> author.
> Type t;
> Type& ref = t; // reference
> Type* p = &t; // address_of


I think the & in that book doesn't mean the reference. The author
referred them to const address-of, non-const address-of operators. I
don't have the book handy and may be wrong.

> > What are are the differences between built-in and global things on a
> > user-defined class?

>
> Built-in means provided by the compiler. global means globally
> accessible.


Operators including the assignment operator are all built-in things in
the language. All functions including ctors, dctor are all not
built-ins, right?

And only operators are global, right?

How can the built-in and global properties affect a class?

> > When a programmer defines a class, are there some built-in (or global)
> > operators or functions be added to the class automatically or
> > synthesized by the language.

>
> Yes, we've discussed them all, ctor, copy, d~tor and op== are
> automatically generated for you. The address_of and reference are
> builtin. What you need to know is what happens when you start providing


That is op= but not op== [double equal marks], right?

Are there exactly 6 members:
ctor
copy ctor
dctor
op=
& (address-of)
& (reference)
will be provided automatically for a class?

I even learnt that someone mentioned two more:
, (comma)
.. (dot)

I am still not clear on the exact list of all automatically provided
members (data and or functions).

> you own ctors.
>
> >
> > > class A { };
> > > int main()
> > > {
> > > A a; // a variable
> > > A* p_a; // a pointer to nothing
> > > p_a = &a; // a pointer to the a variable (&a is address_of a)
> > > A& r_a(a); // a reference to to a (r_a is a reference to a)
> > > }
> > >
> > > >
> > > > I still want to know which members will (or have the chance to) be
> > > > provided automatically for a class? Which members can not be inherited
> > > > from the parent classes? Could you master help me?
> > >
> > > i'm no master.
> > > All virtual member functions are inherited by a Child class. Of course,
> > > that doesn't inlude constructors and destructors nor any operator.
> > > Which makes perfect sense since these are specialized for the Parent
> > > class.
> > > Look at it this way, any "function" that generates / initializes an
> > > object of type Parent can't be overloaded or overridden in its
> > > derivatives. The Child class can't overide a ctor, for example.

> >
> > Are there only these four members:
> >
> > default constructor,
> > copy constructor,
> > assignment operator,
> > destructor
> >
> > will not be inherited from parent classes?

>
> None are "inherited". The parent class can only use them. In some
> cases, the destructor is declared as virtual to support polymorphism,
> in that case its the virtuality thats inherited. The Child class needs
> its own ctors, d~tor and op=.
>
> >
> > As they will be provided (synthesized or predefined) for the child
> > classes by the language.

>
> That doesn't change the fact that the Child class needs its own. When
> the Child type is used to create an object, the compiler needs a base
> class ctor to complete the creation of the object (2 ctors are
> invoked).
>
> >
> > (But how what about the others, how many in total members will be
> > provided automatically? Which are those?

>
> That has already been discussed.
> Look at it this way, if you write a class without definitions, isn't
> the compiler still able to generate, copy, destroy and assign the
> object? How does it do that?
>
> class A { };
>
> int main()
> {
> A a; // ctor
> A another(a); // copy ctor
> a = another; // assignment op
> std::cout << "&a = " << &a << std::endl; // address_of
> A& ref = another; // reference
> std::cout << "&ref = " << &ref << std::endl;
> // a = a + another; // fails, why?
> }
>
> >
> > And which can not be inherited? I ever wrote some example code, but
> > still can not get a complete and detail list of these special
> > functions. Thank you.)

>
> Thats a deep issue. What is inherited is any public or protected
> function that isn't a ctor, d~tor or assignment. Why don't you code


Thanks for this confirmation. I'll code more exercises and go back to
ask for your help when I get problems.

(but I ever leant that even private members can be inherited though
cann't be referred to in the child classes or objects of child classes,
am I right?)

> these? Write 2 classes with std::cerr outputs in their functions and
> watch what happens. You should leave inheritance out of the picture
> until you understand how classes work.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lists of synthesized and inherited class members lovecreatesbea...@gmail.com C++ 0 11-11-2006 08:00 AM
class members vs instance members hdixon Python 3 07-09-2006 06:56 PM
Converting synthesized VHDL/Verilog to spice netlist Noohul Ali VHDL 2 04-28-2005 11:25 AM
Quartus II v3, Circuit after synthesized? Aoniti VHDL 1 05-25-2004 05:26 PM
Can nested class members access private members of nesting class? CoolPint C++ 8 12-14-2003 02:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57