|
I'm sure you do. Do your own homework. Otherwise, you'd still fail your course.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
using System;
class FuzzyDiceThingy
{
static void Main()
{
}
}
I've left out a few minor details, so just fill those in and you're ready to go!
Or better yet make an attempt yourself at solving the assignment and ask for help with specific problems that arise, not just posting your homework and hoping someone will do it for you.
|
|
|
|
|
I voted only 4, since you did not provide NUnit fixture, which is essential
to verify the lot.
|
|
|
|
|
|
Sure. Fork over about US$10,000 (cash, up front) and I'll do your homework for you. Pity, you won't learn anything so you can actually pass the course.
|
|
|
|
|
Given the following class hyerarcy I'm trying to figure out how to explicitly call the Base class implimentation of a virtual method (in this case Name()) instead of the Child class implimentation:
class Base
{
public virtual void Name()
{
Console.Writeline( "Base" );
}
};
class Child : Base
{
public override void Name()
{
Consol.Writeline( "Child" );
}
};
So far the only way I've been able to figure out how to do this is to impliment another method on Child, something like
...
public void BaseName()
{
base.Name();
}
...
But I don't want to have to impliment this method, I want to call the Base class Name method from outside of Child.
In C++ this would be done by using the static binding operator (: , like so.
Child c;
c.Base::Name();
It seems like there has to be something equivalent in C#.
Thanks
Matt Schuckmann
|
|
|
|
|
mschuckmann wrote: Child c;
c.Base::Name();
Cast the child to base:
<br />
Child c;<br />
((Base) c).Name();<br />
(I hope that works, I didn't test it.)
|
|
|
|
|
Unfortunately, this doesn't work. I did try it.
|
|
|
|
|
Dang, I put my foot in it again.
From http://msdn2.microsoft.com/en-us/library/aa645767(VS.71).aspx[^]
Note that it is possible to invoke the hidden virtual method by accessing an instance of D through a less derived type in which the method is not hidden.
This must be one of those naughty things that C++ allows that C# fixed.
|
|
|
|
|
Of course ! that's how you can do it, at the expense of some new method names.
Here is my experiment:
class class1 {
public virtual void print() { basePrint(); }
public void basePrint() { log("class1"); }
}
class class2 : class1 {
public override void print() { log("class2"); }
}
class class3 : class2 {
public override void print() { log("class3"); }
}
public void Test() {
class3 a=new class3();
a.print();
a.basePrint();
class1 b=new class3();
b.print();
b.basePrint();
}
it does print:
class3
class1
class3
class1
at the expense of 1 additional method (basePrint in the base class)
[EDIT: there is absolutely no need for a second method in class2, what was I thinking?]
I still would prefer something that strips the specialization (but without copying data),
so one could write b.base.print(), which would mean print() needs no sibbling.
-- modified at 17:55 Monday 2nd July, 2007
|
|
|
|
|
That's not even right the immediate base of class3 is class2 not class1.
And who wants to pollute their code with a bunch of extra methods when there should a be a way to syntactically statically bind to any method in the inheritance tree.
Yes it's not something you need to do often and it might mean that there is something wrong with your design but there still should be a way to do it, it's not unsafe.
|
|
|
|
|
mschuckmann wrote: the immediate base of class3 is class2 not class1
That is easily fixed by adding a new basePrint() at each level
mschuckmann wrote: pollute their code
I agree completely; now if its only for one method (Serialize) one might choose to live
with it, lacking an alternative in the given context.
|
|
|
|
|
|
+ if you want to call print from class1 you should use this syntax:
((class1)b).print();
where class1 is the base class.
|
|
|
|
|
Hi Matt !
I think you cant:
1.
if you have a Base object or a Base-derivative pointed to by a Base reference,
it will do the virtual call, as intended by the virtual keyword.
2.
there is the "base" keyword, but its use is restricted (see paragraph 7.5.8 in the C# ref man)
to a few places, all inside classes that derive from the base class.
So yoy cant do myObject.base.methodname()
Conclusion: the virtual stuff really hides the base methods/properties.
And my first impression is that is how it should be.
Why is it you want to get at the base implementation from outside of the class anyway ?
There is of course a trick to do it, by providing a Clone() method in the base class,
something that takes a Base or Base-derivative and creates a new Base object, equivalent
to the base-part of the object (similar to a copy constructor), stripping off all
specialization.
|
|
|
|
|
Thanks for the reply and that's pretty much what I thought that you can't.
This kind of came up from a friend of mine who is trying to impliment something like the boost serialization library in C# in that he has a secondary class that is walking the inheritance tree of the class to serialize by exlicitly serializing the base classes states. It kind of does this in a funny way and I'm not entirely convinced it's the right way.
Beyond that I have run into times where it was handy to do this, usually because something beyond my control was implimented improperly.
|
|
|
|
|
I see; in the mean time PIEBALDconsult has come up with a good approach that may well
fit your needs.
|
|
|
|
|
|
Sorry
with a spoonful of lateral thinking I read your sentence "Note that it is possible to invoke the hidden virtual method by accessing an instance of D through a less derived type in which the method is not hidden" as "WTF just give the method a name that remains visible...".
|
|
|
|
|
That wasn't my sentence; it's a quote from the linked document... I need to find a clearer way of indicating such.
|
|
|
|
|
There is no escape, it is your post that led to a solution...
|
|
|
|
|
Hi,
How many maximum Threads can be created in CLR Thread pool?
|
|
|
|
|
The standard thread pool allows 25 threads per processor, but there are a number of improved thread pool implementations that allow you to go beyond this. You may want to look at this[^] implementation.
|
|
|
|
|
MSDN does not give a specific number, but it does list a number of remarks.
In short, you dont know (which means it may vary), and dont exagerate !
|
|
|
|
|
Hi!
I want to to fire a number of asynch method calls from a main thread and have the main thread return true synchronously if the method calls all return true, otherwise false.
The asynch method calls should have a timeout which makes them return false. How to best implement in .NET 2.0? Performance is an issue!
Pseudo code:
<br />
public void main() <br />
{<br />
SynchObj sObj = new SynchObj();<br />
bool allTrue = sObj.SynchCall();<br />
}<br />
<br />
public class SynchObj<br />
{<br />
public bool SynchCall() <br />
{<br />
bool allTrue = false;<br />
<br />
<br />
return allTrue;<br />
}<br />
}<br />
<br />
public class AsynchObj <br />
{<br />
public bool AsynchCall(int timeout)<br />
{<br />
}<br />
}<br />
|
|
|
|