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

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 2447
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.com

"murat oguzalp" <murat_oguzlap> wrote in message
news:%2****************@TK2MSFTNGP10.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.com

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.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.<constructor>(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_oguzlap> wrote in message
news:%2****************@TK2MSFTNGP10.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**************@TK2MSFTNGP12.phx.gbl...

"murat oguzalp" <murat_oguzlap> wrote in message
news:%2****************@TK2MSFTNGP10.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
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){...
2
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...
6
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...
7
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
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...
2
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...
12
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. ...
11
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...
19
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.