473,498 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java like constructor calling constructor

Hello,

Probably I am not seeing it now, but is it possible for constructor(int) to
call constructor() ?

class A
{
private:
int x, y;
public:
A();
A(int);
};

A::A()
{
x = y = 0;
}

A::A(int x)
{
// call A::A() ?
// in Java, it is: this()
}

Or I have to write a small function like:
A::ctor()
{
// do common stuff here
}
A::A()
{
ctor();
}
A::A(int x)
{
ctor();
// more stuff here
}
--
Elias
Jul 22 '05 #1
5 1479
lallous wrote:
Hello,

Probably I am not seeing it now, but is it possible for
constructor(int) to call constructor() ?

[SNIP]

No. It is being discussed as a possible future feature (delegating
constructor???) but right now all you can do is to make a 3rd (named)
function and call that one from both constructors. This - of course - lacks
the capability of sharing initializer lists.

--
Attila aka WW
Jul 22 '05 #2
"lallous" <la*****@lgwm.org> wrote...
Probably I am not seeing it now, but is it possible for constructor(int) to call constructor() ?
No. Constructors don't have names, they cannot be called.
[...]

Or I have to write a small function like:
A::ctor()


Yes.

V
Jul 22 '05 #3
lallous wrote:
Hello,

Probably I am not seeing it now, but is it possible for
constructor(int) to call constructor() ?
No.
Or I have to write a small function like:


Either that, or use default values for the parameters of your A(int)
constructor.

Jul 22 '05 #4
On Fri, 23 Jan 2004 16:41:57 +0200, Attila Feher wrote:
lallous wrote:
Hello,

Probably I am not seeing it now, but is it possible for
constructor(int) to call constructor() ?

[SNIP]

No. It is being discussed as a possible future feature (delegating
constructor???) but right now all you can do is to make a 3rd (named)
function and call that one from both constructors. This - of course - lacks
the capability of sharing initializer lists.


Well another thing that sometimes works is creating a baseclass that has
the common code in its constructor.

HTH,
M4

Jul 22 '05 #5
On Fri, 23 Jan 2004 16:32:55 +0200 in comp.lang.c++, "lallous"
<la*****@lgwm.org> was alleged to have written:
is it possible for constructor(int) to call constructor() ?


This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[10.3] Can one constructor of a class call another constructor of the
same class to initialize the this object?" It is always good to check
the FAQ before posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
Jul 22 '05 #6

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

Similar topics

1
2208
by: Raja | last post by:
I have a java class thats trying to call something in python. This works fine when i do a jythonc on the python script. When i call another python script from the __init__ of my called python...
18
2967
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
1
9582
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
6918
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
2881
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
5
6256
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
3874
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented...
9
23719
by: Morten Lemvigh | last post by:
Is it possible to pass a pointer to a constructor or a class definition as argument to a function? Maybe in a way similar to passing function pointers...? The function should construct a number...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.