|
First of all the proper way to inherit is :
public ClassB:ClassA
{
}
Secondly, when you are instianting ClassB it calls the parent constructor first and then instiante the derived class. For instance
ClassB cb = new ClassB()---> it calls the Parent no value(default constructor) first and then
public classB()
{
}
Thirdly, ClassB cb = new Classb(2)-->it calls the Parent value constructor in ur case is
public classA(int i)
{
} and then the dervied class constructor
public classB(int i)
{
//some code
}
hope it may help
|
|
|
|
|
Are you sure about that second case? As far as I understand (and can reproduce), if you instantiate ClassB cb = new ClassB(2) it calls the default constructor of ClassA first and then the overloaded constructor of ClassB . It never calls the overloaded constructor of ClassA as you say.
This is of course if you don't specify for the constructors whether they should be calling other constructors. If I wanted the overloaded constructor of ClassB to first call the overloaded constructor of ClassA as opposed to the default constructor of ClassA, I would have had to specify it as:
public ClassB(int i) : base(i)
{
}
Am I missing something?
|
|
|
|
|
Try the following:
class classA
{
public classA() : this(0)
{
}
public classA(int i)
{
}
}
class classB : classA
{
public classB() : base()
{
}
public classB(int i) : base(i)
{
}
} With this, calling the classB constructors will result in the appropriate classA constructors being called. If however, you want to explicitly perform some code in response to the constructors, I would create an OnInit method, and call it from public classA(int i) . This means that all of the paths through to it will be handled.
|
|
|
|
|
Pete O'Hanlon wrote: public classB() : base()
{
//some code
}
I think the call to base() is not needed here. When classB is instantiated, parameterless constructor of base class will be called.
|
|
|
|
|
Thanks, but this won't exactly do what I'm looking for. I'm looking for a way to have an instantiation of ClassB cb = new ClassB(1) make a call to both constructors of ClassB as well as the default constructor of ClassA.
The way you suggest would result in an instantiation as above to only call the overloaded constructors of both classes, but not the default onstructor of ClassA.
Not to worry though. The more I think about it, the more I realise that I'm trying to use OOP in a way it's not meant to be used. I've found another way to achieve what I want anyway.
Also, I think your suggestion of an OnInit method makes better sense as well.
Thanks again.
|
|
|
|
|
but how do I get it to call both?
You don't, cause you can only have on base instance, so you can't call two constructors. You'll have to put the code from both base class constructors into two protected methods and call each from the respective base class constructor, and call both from the derived class constructor.
|
|
|
|
|
Makes sense. I realised afterwards that this is really what OOP is all about. Thanks for the response.
|
|
|
|
|
class classB : classA
{
public classB() : this(5)
{
}
public classB(int i) : base("laser")
{
}
}
calling classB() will run both
betonglasermur.FeedDwarf(pur_is, 17);
ProcessStartupInfo.AintNotCreateNoWindow = (false && !true) != (true || false) ? false == true ? true : false : (true != false && false);
Morgonen är tröttmans mecka
|
|
|
|
|
Huh? You've got me nicely confused here. Are you being serious?
|
|
|
|
|
|
hadad wrote: how can I use the FileIOPermission class
I know many programmers come lately don't seem to believe that they need to read the documentation but one can actually find out how to use the FileIOPermission class by reading the documentation[^]
led mike
|
|
|
|
|
I really don't get it...
Do people just type in random words and hope it will work?
Or copy code off the web and jam it into their code and hope it works?
WTF?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Do people just type in random words and hope it will work?
Or copy code off the web and jam it into their code and hope it works?
Yes
Mark Salsbery wrote: WTF?
I'm pretty sure this was the impetus behind the invention of the Filet-O-Fish
led mike
|
|
|
|
|
class PleaseWork
{
public void getPermission ()
{
MyComputer.GetBinnaryPermission (directory);
}
}
|
|
|
|
|
If I start typing "binnary" with two "n"s I'm going to scream.
It's like getting a stupid song stuck in my head...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes !
stupid melody that you hear when you weak up in the morning.
BinnaryWriter
..nice class we shoud ask Microsoft to bring us a 'Binnary' Namespace
|
|
|
|
|
Be fair. He was googling BinnaryWriter, which obviously doesn't return too many hits.
|
|
|
|
|
Pete O'Hanlon wrote: Be fair.
Hmm. Let me think about it. NO!
led mike
|
|
|
|
|
|
:cough:
Thanks dude, I needed a good laugh and that was a great one!
led mike
|
|
|
|
|
Hello friends, I couldn't find much info on how to copy/paste text and preserve the formatting from other applications (like World, PowerPoint) to webbrowser control in C#. I was able to copy/paste text from e.g words but i loose all the formatting when i paste text to the webbrower control like "bullets, indentation and other normal features).
So my real question is that, can we Paste the formated text the way it was when copied from other applications. I tried like this but no success. Could you suggest me through your experience or thoughts or any kind resources.
if (Clipboard.ContainsText())
{
IHTMLTxtRange range = doc.selection.createRange() as IHTMLTxtRange;
range.pasteHTML(Clipboard.GetText(TextDataFormat.Text));
}
Thanks
|
|
|
|
|
Hi,
I am used to VB6 reading a few header items below each other out of a text file followed by some columns of data such as:
fh1 = FreeFile
Open inPath For Input As #fh1
Input #fh1, projfile.name
Input #fh1, projfile.projdate
Input #fh1, projfile.version
For X = 1 To intNumVars
Input #fh1, Bas(X).name, Bas(X).Min, Bas(X).Max, Bas(X).ave,
Next X
Close(fh1)
I have been through a lot of material on StreamReader, BinaryReader etc and getting stuck. Any help (code examples) or pointers to articles, chapters would be much appreciated. The writing of the info to the file seems easy with :
StreamWriter outFS = new StreamWriter(new FileStream(outFile, FileMode.OpenOrCreate, FileAccess.Write));
outFS.WriteLine(strModelDesc1);
outFS.WriteLine(strModelDesc2);
outFS.WriteLine("{0},{1},{2}"intLayers, intStats, decAve);
outFS.Close();
thanks
Ian
|
|
|
|
|
Hello,
How can I get the path of the current user Temp file.
Dad
|
|
|
|
|
System.IO.Path.GetTempPath();
Edit:
Environment.GetEnvironmentVariable("TEMP");
or
Environment.GetEnvironmentVariable("TMP");
will also work but
1. It gives the path in 8.3 format
2. If at any point in the future MS changes the Environment variable it may break(!) so I'd use the initial suggestion.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Google.
For cryin' out loud, put some freakin' effort into your work. Asking here takes MANY TIMES LONGER than using google.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|