473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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

Nov 22 '05 #1
3 4296

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.8), 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.

Nov 22 '05 #2
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

Nov 22 '05 #3
In article <11**********************@o13g2000cwo.googlegroups .com>,
<in******@mail2dreamer.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?
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: seberino | last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows. This causes confusion for 1 item tuples since (5) can be interpreted as a tuple OR as the number 5 in a mathematical...
4
by: Newbie | last post by:
Is it possible to set up an event handler or something else so that when *any* link on the page is clicked it 'fires-up', executes some JS and then continues to process the link that was clicked?...
5
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on this...
2
by: BigCalm | last post by:
I'm currently modifying a daemon (on AIX unix) which is primarily C source. At the moment, the daemon sleeps 30 seconds before checking if it has anything to do, but I'd like to improve this so...
64
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be...
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
10
by: printline | last post by:
Hello i have some php code where i echo out somethings from a database into a table. What i need is some php code to show something else than what i am getting from the database. Here is an...
15
by: UberGirl | last post by:
Hi, I'm a novice... just trying figure out something simple, I'm sure. I've got a script within my <head> tags to show/hide divs on click: function showHide(divID, imgID){ if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.