473,325 Members | 2,342 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,325 software developers and data experts.

MultiLevel Inheritance

Here's a scenario:

MainObject
{
ObjectB myB;
myB = new ObjectB(P, true);
}

ObjectA
{
variable v1;
variable v2;
ObjectA(param P)
{
v1 = P.something;
v2 = P.somethingelse;
}
}

ObjectB: ObjectA
{
ObjectC myC;
ObjectB(param P, bool check) : base(P)
{
if(check)
myC = new ObjectC(P);
}
}

ObjectC : ObjectB
{
constructorObjectC(param P): (base P)
{
}
}
==================

I am trying to do the above but I am getting errors. I want to create Object
C only if the boolean is true and not create it otherwise. How can I go about
doing this?

Thanks in advance for your help.
Oct 2 '08 #1
3 2386
amir <am**@discussions.microsoft.comwrote:
Here's a scenario:
You've written a lot of pseudocode without explaining what you want it
to do. Could you try to write what you want in as close to real C# as
possible? Also explain what you want to achieve.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Oct 2 '08 #2
On Thu, 02 Oct 2008 15:08:02 -0700, amir <am**@discussions.microsoft.com>
wrote:
[...]
I am trying to do the above but I am getting errors. I want to create
Object
C only if the boolean is true and not create it otherwise. How can I go
about
doing this?
Next, please remember to be _specific_ about your question. For example,
you write "but I am getting errors". What errors? Where? Under what
circumstances? When you compile? When you run the application?

It's also helpful if you actually post code that compiles. As opposed to
code that has a method named "constructorObjectC" that illegally tries to
call a base constructor.

That said, my mind-reading hat seems to be working okay today, and I can
explain to you that at a minimum you have an illegal call to the base
constructor in ObjectC, because ObjectB only has a two-argument
constructor and you're trying to call a single-argument constructor.

Furthermore, if you posted the exact code that you compiled then obviously
you will want to fix your constructor so that it's named "ObjectC" instead
of "constructorObjectC". In that case, you also will want to add an
accessibility modifier to the constructors so that they aren't private.

Which of these mistakes actually applies to the foremost problem you're
running into I can't say because you haven't shared enough information
about the errors. But hopefully the code you posted is close enough to
the code you're actually trying to compile that the above is in some way
helpful.

Pete
Oct 2 '08 #3
hope the below helps out

DaveL
namespace console1
{
public static class console1
{
public static void main()
{
AbstractTest o1 = new Inherit1();
AbstractTest o2 = new Inherit2();
AbstractTest o3 = new Inherit3();
}
}
// in the namespace

public abstract class AbstractTest
{
public int Field1;
public int Field2;
public AbstractTest()
{
}
public virtual String HelloWorld()
{
Console.WriteLine("In Abstract Class");
return "";
}
}
public class Inherit1 : AbstractTest
{
public Inherit1()
{
}
public override string HelloWorld()
{
Console.WriteLine("Do Somthing Different");
return "";
}
}
public class Inherit2 : Inherit1
{
public Inherit2()
{
}
}
public class Inherit3 : AbstractTest
{
public Inherit3()
{
}
}
}
"amir" <am**@discussions.microsoft.comwrote in message
news:EA**********************************@microsof t.com...
Here's a scenario:

MainObject
{
ObjectB myB;
myB = new ObjectB(P, true);
}

ObjectA
{
variable v1;
variable v2;
ObjectA(param P)
{
v1 = P.something;
v2 = P.somethingelse;
}
}

ObjectB: ObjectA
{
ObjectC myC;
ObjectB(param P, bool check) : base(P)
{
if(check)
myC = new ObjectC(P);
}
}

ObjectC : ObjectB
{
constructorObjectC(param P): (base P)
{
}
}
==================

I am trying to do the above but I am getting errors. I want to create
Object
C only if the boolean is true and not create it otherwise. How can I go
about
doing this?

Thanks in advance for your help.

Oct 2 '08 #4

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

Similar topics

0
by: Reimar Bauer | last post by:
Dear all is there an encryption/decryption method available with multilevel passwords? Thanks for any help Reimar Bauer --
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
2
by: Rythm Music | last post by:
I am trying to get some help on creating a Multilevel Hierarchial Datagrid. What I mean is that the Hierarchial level is unknown. There could be many related records or none. Also there could be...
34
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my...
0
by: virendra | last post by:
hi, I am working on crystal report 9 in asp.net. I created multilevel dynamic grouping in CR. if page is load firsttime. and i am giving firstlevel of grouping or whatever it's working fine. but...
0
by: sphemamalini | last post by:
respected sir, i need to know whether DB2 is good for doing our project based on multilevel security on database.shall we use java for creating web page.we use java as front end.DB2 as back end.DB2...
0
by: nintesa | last post by:
I'm using Oscommerce, Joomla, Mambo ecc... everyone of these have a good multilevel admin panel. Now I'm developing a new indipendent little application ad I'm wondering if there is a small...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.