Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > IS CONSTRUCTOR A SPECIAL MEMBER FUNCTION? OR SOMETHING ELSE HAVING THE SYNTAX OF FUNCTION?

Reply
Thread Tools

IS CONSTRUCTOR A SPECIAL MEMBER FUNCTION? OR SOMETHING ELSE HAVING THE SYNTAX OF FUNCTION?

 
 
infinity@mail2dreamer.com
Guest
Posts: n/a
 
      11-17-2005
Hi all,
Is constructor a special member function? But I don't think it is
either a member function or even a special member function although it
has the syntax of a function. I think it confused with a function due
to the similar syntax. If i am wrong give some proof and prove you
points. I think its a fundamental doubt.
~Thanks
Infinity

 
Reply With Quote
 
 
 
 
Neelesh Bodas
Guest
Posts: n/a
 
      11-17-2005

infin...@mail2dreamer.com wrote:
> Hi all,
> Is constructor a special member function? But I don't think it is
> either a member function or even a special member function although it
> has the syntax of a function. I think it confused with a function due
> to the similar syntax. If i am wrong give some proof and prove you
> points. I think its a fundamental doubt.
> ~Thanks
> Infinity


The C++ standard chapter 12 paragraph 1 :

"The default constructor (12.1), copy constructor and copy assignment
operator (12., and destructor (12.4) are special member functions.
The implementation will implicitly declare these member functions for a
class type when the program does not explicitly declare them..."

Hence proved.

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      11-17-2005
infin...@mail2dreamer.com wrote:
> Hi all,
> Is constructor a special member function? But I don't think it is
> either a member function or even a special member function although it
> has the syntax of a function. I think it confused with a function due
> to the similar syntax. If i am wrong give some proof and prove you
> points. I think its a fundamental doubt.
> ~Thanks
> Infinity


WHY ARE YOU YELLING AT US IN YOUR SUBJECT LINE?!

Constructors are special member functions. In particular, a constructor
does not get inherited and cannot be virtual. On the first point,
consider:

struct Base
{
Base( int );
void Foo();
};

struct Derived
{
Derived() : Base( 0 ) {}
};

void Bar()
{
//Derived d( 0 ); // Error! Cannot use Base's constructor

Derived d; // Ok. Use Derived's constructor
d.Foo(); // Ok. Foo is inherited, unlike Base::Base()
}

The destructor and assignment operator are also special.

Cheers! --M

 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      11-17-2005
In article < .com>,
<> wrote:
>Is constructor a special member function? But I don't think it is
>either a member function or even a special member function although it
>has the syntax of a function. I think it confused with a function due
>to the similar syntax. If i am wrong give some proof and prove you
>points. I think its a fundamental doubt.


A member function is a function, that's a member of a class.

A constructor is a member function.

It can also fall into the so-called category of "special" member function.
Section 12p1 of Standard C++ reads "The default constructor, copy
constructor and copy assignment operator, and destructor are
``special member functions''."

Is there some other underlying question about them though?
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
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
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
How to find and replace something that is nested inside something else? alainfri@gmail.com Perl Misc 4 05-31-2007 11:50 PM
define a copy constructor in a class having data member as an object of another class dalu.gelu@gmail.com C++ 11 11-09-2006 07:49 PM
umm... something... template(s)... something else... pointer(s)... and such... 0.o yah, I'm hopeless and clueless o.0 C++ 4 10-13-2004 10:34 PM
Constructors are having a special signature, different from ordinary member functions ? Razvan Java 1 09-30-2004 06:12 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