473,395 Members | 1,652 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,395 software developers and data experts.

calling overloaded constructor from constructor

hi everybody

i suppose this question has been answered a countless times, but i can't
seem to find the answer...

how do i call an overloaded version of a constructor from a constructor?
suppose something like this:

class A
{
int field;
A(int i){field = i;}
A()
{
// and here comes the guesswork:
A(1);
}
};

what i want to do is calling another constructor with default arguments.

thanks for any help and hints

- michael
Dec 7 '05 #1
2 3988
* Michael Wild:

i suppose this question has been answered a countless times, but i can't
seem to find the answer...

how do i call an overloaded version of a constructor from a constructor?


Within the same class you can't.

You can introduce an artificial base class, use default values, or use
an init-function.

The latter is a FAQ.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 7 '05 #2
Alf P. Steinbach wrote:
* Michael Wild:
i suppose this question has been answered a countless times, but i can't
seem to find the answer...

how do i call an overloaded version of a constructor from a constructor?


Within the same class you can't.

You can introduce an artificial base class, use default values, or use
an init-function.

The latter is a FAQ.


Thanks. I'll stick with the init function then.
Dec 7 '05 #3

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

Similar topics

3
by: Christian Dieterich | last post by:
Hi, I need to create many instances of a class D that inherits from a class B. Since the constructor of B is expensive I'd like to execute it only if it's really unavoidable. Below is an example...
2
by: Grandma Wilkerson | last post by:
Hi, I have a class whose constructor accepts a Socket as an argument. The constructor then makes a call to Socket.BeginReceive(). The callback delegate passed to BeginReceive() is a method of my...
5
by: Alan Seunarayan | last post by:
Hello all, I need to know if I can call a C# constructor in the same way VB.NET and JAVA can. For example: class myClass { public myClass() { Console.WriteLine("Hello from constructor 1"); }...
1
by: R.Balaji | last post by:
Hi, How do I call the overloaded construction when I create the instance using the Reflection? for eg) namespace MySpace { Interface IOrganization
20
by: lars.uffmann | last post by:
I have to work on a rather big project that a bunch of people wrote and that has no useful documentation at all, my C++ has rusted in a bit, now I stumbled over a constructor that looks something...
3
by: ES Kim | last post by:
iterator classes provide overloaded operators like this in general: template <typename T> class Iterator { Iterator operator++(int); // postfix ++ T& operator*(); }; Iterator<int> i;
1
by: Avi | last post by:
Hi all, I'm trying to write an exception with overloaded constructor, where one will raise an exception while the other will only write to log. However, trying the follwoing did not work throw...
4
by: ali | last post by:
Hi, I am new to C++ and trying to understand how to work on Inheritance and Operator overloading. I understand that the derived class can pass the base class constructor in its constructor...
5
by: Sathyaish | last post by:
/* I am writing this C# program because I forgot the syntax for calling a parameterized constructor from a non-parameterized one within the same class. I was coding in Java and just typed it...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.