I have a class/constructor hiearchy that functions correctly as illustrated
below (thanks to Ken Kolda's earlier newsgroup assistance.) If a client
instantiates object D, eg. D m_D = new D(str_arg), it climbs up the ctor
stack until B(string str) handles it.
A();
B();
B(string str)
{
do_string_Stuff; }
C();
C(string str) : base(str);
D();
D(string str) : base(str);
Now for the change. I have a class that has this ctor signature.
D ( long n_arg, string str) // :base(str) won't work anymore. will
it have to be :base(n_arg, str)
D m_D = new D(long n_arg2, string str_arg ) would work, just adding an
additional string argument, but I want to get up to the overloaded ctor in
B. How do I change this object design in the least invasive manner? Do I
have to add new constructors with the additional n_arg to C and B for this
to work as per the following?
A();
B();
B(string str)
{ do_string_stuff; }
B (long n_arg, string str)
{ do_string_stuff; }
C();
C(string str) : base(str);
C( long n_arg, string str) : base(n_arg, str);
D();
D(string str) : base(str);
D (long n_arg, string str) : base(n_arg, str);
Thank you very much,
-greg 6 1277
hazz <ha**@sonic.net> wrote: I have a class/constructor hiearchy that functions correctly as illustrated below (thanks to Ken Kolda's earlier newsgroup assistance.) If a client instantiates object D, eg. D m_D = new D(str_arg), it climbs up the ctor stack until B(string str) handles it.
A();
B(); B(string str) { do_string_Stuff; }
C(); C(string str) : base(str);
D(); D(string str) : base(str);
Now for the change. I have a class that has this ctor signature. D ( long n_arg, string str) // :base(str) won't work anymore. will it have to be :base(n_arg, str)
base(str) should work absolutely fine. Why do you think it wouldn't?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"hazz" <ha**@sonic.net> wrote in message
news:O%***************@TK2MSFTNGP12.phx.gbl... I have a class/constructor hiearchy that functions correctly as
illustrated below (thanks to Ken Kolda's earlier newsgroup assistance.) If a client instantiates object D, eg. D m_D = new D(str_arg), it climbs up the ctor stack until B(string str) handles it.
A();
B(); B(string str) { do_string_Stuff; }
C(); C(string str) : base(str);
D(); D(string str) : base(str);
Now for the change. I have a class that has this ctor signature. D ( long n_arg, string str) // :base(str) won't work anymore. will it have to be :base(n_arg, str)
It does has to work !
It will also work :this( str) which call the other constructor of D
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
thanks for responding Jon.
base(str) DID work absolutely fine as you correctly pointed out.
However, D (long n_arg, string str) has been added to the mix.
So should D (long n_arg, string str) : base(n_arg, str) work absolutely
fine as per my best attempt to try to explain how I 'thought' it might work
as per the psuedocode that follows immediately;
A();
B();
B(string str)
{ do_string_stuff; }
B (long n_arg, string str)
{ do_string_stuff; }
C();
C(string str) : base(str);
C( long n_arg, string str) : base(n_arg, str);
D();
D(string str) : base(str);
D (long n_arg, string str) : base(n_arg, str);
If I am missing the obvious, please let me know.
Appreciatively,
-greg
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... hazz <ha**@sonic.net> wrote: I have a class/constructor hiearchy that functions correctly as illustrated below (thanks to Ken Kolda's earlier newsgroup assistance.) If a client instantiates object D, eg. D m_D = new D(str_arg), it climbs up the ctor stack until B(string str) handles it.
A();
B(); B(string str) { do_string_Stuff; }
C(); C(string str) : base(str);
D(); D(string str) : base(str);
Now for the change. I have a class that has this ctor signature. D ( long n_arg, string str) // :base(str) won't work anymore.
will it have to be :base(n_arg, str)
base(str) should work absolutely fine. Why do you think it wouldn't?
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Thank you Ignacio. You are mentioning the 'this' keyword. Like this;
A();
B();
B(string str)
{ do_string_stuff; }
C();
C(string str) : base(str);
D();
D(string str) : base(str);
D ( long n_arg, string str) : this
D m_D = new D(n_arg, str_arg) would then instantiate properly and
additionally would pass the string up to B. Correct?
thx, -greg
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:eo**************@TK2MSFTNGP10.phx.gbl... "hazz" <ha**@sonic.net> wrote in message news:O%***************@TK2MSFTNGP12.phx.gbl... I have a class/constructor hiearchy that functions correctly as illustrated below (thanks to Ken Kolda's earlier newsgroup assistance.) If a client instantiates object D, eg. D m_D = new D(str_arg), it climbs up the ctor stack until B(string str) handles it.
A();
B(); B(string str) { do_string_Stuff; }
C(); C(string str) : base(str);
D(); D(string str) : base(str);
Now for the change. I have a class that has this ctor signature. D ( long n_arg, string str) // :base(str) won't work anymore.
will it have to be :base(n_arg, str)
It does has to work ! It will also work :this( str) which call the other constructor of D
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
hazz <ha**@sonic.net> wrote: thanks for responding Jon. base(str) DID work absolutely fine as you correctly pointed out. However, D (long n_arg, string str) has been added to the mix. So should D (long n_arg, string str) : base(n_arg, str) work absolutely fine as per my best attempt to try to explain how I 'thought' it might work as per the psuedocode that follows immediately;
Yes, it should work fine. So long as you either explicitly call a
constructor of the base class with appropriate arguments, or call
another constructor of the current class, or don't do anything and
leave the compiler to add an implicit base() call (which obviously has
to be valid) you should be okay.
See http://www.pobox.com/~skeet/csharp/constructors.html for more
information.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
To be syntactically correct , > D ( long n_arg, string str) : this(str)
"hazz" <ha**@sonic.net> wrote in message
news:eh*************@TK2MSFTNGP12.phx.gbl... Thank you Ignacio. You are mentioning the 'this' keyword. Like this;
A();
B(); B(string str) { do_string_stuff; }
C(); C(string str) : base(str);
D(); D(string str) : base(str); D ( long n_arg, string str) : this
D m_D = new D(n_arg, str_arg) would then instantiate properly and additionally would pass the string up to B. Correct?
thx, -greg
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:eo**************@TK2MSFTNGP10.phx.gbl... "hazz" <ha**@sonic.net> wrote in message news:O%***************@TK2MSFTNGP12.phx.gbl... I have a class/constructor hiearchy that functions correctly as illustrated below (thanks to Ken Kolda's earlier newsgroup assistance.) If a
client instantiates object D, eg. D m_D = new D(str_arg), it climbs up the
ctor stack until B(string str) handles it.
A();
B(); B(string str) { do_string_Stuff; }
C(); C(string str) : base(str);
D(); D(string str) : base(str);
Now for the change. I have a class that has this ctor signature. D ( long n_arg, string str) // :base(str) won't work anymore. will it have to be :base(n_arg, str)
It does has to work ! It will also work :this( str) which call the other constructor of D
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dan Perl |
last post by:
There is something with initializing mutable class attributes that I am
struggling with. I'll use an example to explain:
class Father:
attr1=None # this is OK
attr2= # this is wrong...
|
by: Banaticus Bart |
last post by:
I wrote an abstract base class from which I've derived a few other
classes. I'd like to create a base class array where each element is
an instance of a derived object. I can create a base class...
|
by: Tron Thomas |
last post by:
Under the right compiler the following code:
class Base
{
public:
virtual void Method(int){}
};
class Derived: public Base
{
|
by: hazz |
last post by:
The following classes follow from the base class ' A ' down to the derived class ' D ' at the bottom of the inheritance chain.
I am calling the class at the bottom, "public class D" from a client...
|
by: hamstak |
last post by:
I had developed a custom base page class for the 1.1 framework which I
have now migrated to the 2.0 framework. I discovered that the new
partial class system -- which appears to "automagically"...
|
by: ivan.leben |
last post by:
I want to write a Mesh class using half-edges. This class uses three
other classes: Vertex, HalfEdge and Face. These classes should be
linked properly in the process of building up the mesh by...
|
by: ivan.leben |
last post by:
I am writing this in a new thread to alert that I found a solution to
the problem mentioned here:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8
and to avoid...
|
by: campos |
last post by:
"Effective C++ 3rd Edition" Item 6, P39
-------------------------------------------------------
class Uncopyable {
protected: // allow construction
Uncopyable() {} // and...
|
by: nyathancha |
last post by:
Hi,
How Do I create an instance of a derived class from an instance of a
base class, essentially wrapping up an existing base class with some
additional functionality. The reason I need this is...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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,...
|
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...
| | |