473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling base and this constructor at same time, is possible?

i want to call base and this constructor at the same time. is is possible?

i mean:
B(int a, int b, int c):base(a):this (b)
{
// do something with c
}

at java i used to do that:

B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}

and if yes, how is its syntax.

thanks in advance

alpos

Nov 16 '05 #1
4 2462
Murat,

No, this is not possible. If you want to call the this and base
constructor, then you will have to call "this" constructor which in turn
calls the "base" constructor (in a chain).

In your case, you would have to have B(int, int, int) call B(int) which
in turn would call base(int).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"murat oguzalp" <murat_oguzla p> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
i want to call base and this constructor at the same time. is is possible?

i mean:
B(int a, int b, int c):base(a):this (b)
{
// do something with c
}

at java i used to do that:

B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}

and if yes, how is its syntax.

thanks in advance

alpos

Nov 16 '05 #2
Rakesh,

This is not possible, as you need to indicate whether or not you call
"this" or "base" before any code in the constructor is run.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Rakesh Rajan" <Ra*********@di scussions.micro soft.com> wrote in message
news:83******** *************** ***********@mic rosoft.com...
I don't know if i got ur question right. But you could use the base keyword
for this operation.

Eg:
B(int a, int b, int c)
{
base(a);
this.<construct or>(b);
// do something with c
}
"murat oguzalp" wrote:
i want to call base and this constructor at the same time. is is
possible?

i mean:
B(int a, int b, int c):base(a):this (b)
{
// do something with c
}

at java i used to do that:

B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}

and if yes, how is its syntax.

thanks in advance

alpos

Nov 16 '05 #3

"murat oguzalp" <murat_oguzla p> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
i want to call base and this constructor at the same time. is is possible?

i mean:
B(int a, int b, int c):base(a):this (b)
{
// do something with c
}

at java i used to do that:

B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}


No you didn't; that is not legal java.

In Java, you'd do something like:

B(int a, int b, int c)
{
super(a);
init(b);
}

B(int b)
{
init(b);
}

private init(int b)
{
... common init logic
}

In C#, you do the same.
Nov 16 '05 #4
thaks to everyone for sharing information.
Mike is right. i thought, i could have done it.
but neither java, it's not legitimate
alpos
"Mike Schilling" <ms************ *@hotmail.com> wrote in message
news:eN******** ******@TK2MSFTN GP12.phx.gbl...

"murat oguzalp" <murat_oguzla p> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
i want to call base and this constructor at the same time. is is possible?
i mean:
B(int a, int b, int c):base(a):this (b)
{
// do something with c
}

at java i used to do that:

B(int a, int b, int c)
{
super (a);
this(b);
// do something with c
}


No you didn't; that is not legal java.

In Java, you'd do something like:

B(int a, int b, int c)
{
super(a);
init(b);
}

B(int b)
{
init(b);
}

private init(int b)
{
... common init logic
}

In C#, you do the same.

Nov 16 '05 #5

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

Similar topics

9
27745
by: Giulio | last post by:
why definition of two constructors like these is not possible in c++??? ----------------------- date::date(const int d, const int m, const int y, const int ora, const int mi, const int se){ day_ = d; month_ = m; year_ = y; secondo_ = se;
2
1901
by: William Payne | last post by:
Hello, consider these following two classes. A base class, class MDIChildWindow, and a class inherting from that base class, class Document. In the static base member function callback() I obtain a pointer to the child class and call the function on_mdiactivate() using this pointer. For some reason, the program executes...
6
2099
by: Justin | last post by:
Hello, first time posting. If I have a base class and a derived class, is there only one way to call the base constructor? i.e. Is this the only way I can call the base constructor (presuming the base constructor took an int): Derived::Derived(int a) : Base(a)
7
37699
by: Jo Vermeulen | last post by:
Hello, I was wondering how I could call the base class constructor from a derived class constructor. In Java I could do something like super(parameter); I tried base(parameter);
2
3852
by: Josef Meile | last post by:
Hi, I have this constructor: public CExcelDatabase(string host, string user, string password, string database, bool promptCredentials, int findExcelInstance, bool readOnly) { //Some code comes here
2
3204
by: Sathyaish | last post by:
How does a constructor of one class call another of the same class? When would this mechanism make sense or be required? PS: Two instances I saw are: (a) While using the Singleton pattern (b) While using the Factory pattern
12
5785
by: st_ev_fe | last post by:
I've noticed that when constructing a subclass, the base class get's it's contructors called. Is there some way to avoid this? The base class has one variable, which gets initialised to 0. The subclass's constructor sets this variable to a real value. So first the variable is set to 0, the variable is never used before it once again...
11
3403
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the vtable pointer is made use of.. eg. class one {
19
2214
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit modify come of the classes so they match our purpose better - mostly add a few methods etc. Example: Open source lib has classes Map and Layer...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.