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

Multiple Inheritance w/ Managed C++, how can you access an implementing classes properties after casting it to the base interface?

I have three interfaces, lets call them General, Client, Server.

public interface General
{
public Value{get;}
}

public interface Client : General
{}

public interface Server: General
{
public Value{set;}
}

public class Something : Server, CLient{
}

public class Test{
Something a = new Something();
a as General;
a.Value = 5;
}

THis is essentially what I'm trying to do, but all three interfaces are
in MCPP and for some reason when I try to write to the property Value
it says it can not be accessed. What am I doing wrong? Here is the
actual interface code below, I'll trim out the extraneous methods.

#pragma once

namespace Provider
{

public __gc __interface General : public IDisposable
{

public:
__property NameValueCollection* get_Parameters(void);
};
};

#pragma once

#include "General.h"
namespace Provider
{

public __gc __interface Server : public General
{

public:
__property void set_Parameters(NameValueCollection
*parameters);
};
};

and the CLient, or third interface just adds an additional method. All
I'm trying to do is have the classes that implement server be able to
set properties, and otherwise they can only get them. Thank you in
advance for any help.

Jun 29 '06 #1
2 3407
Well, it's hard to say why your code doesn't run since the code you
posted doesn't even compile. The main problem is the line "a as
General;" which, as written, is completely meaningless --- and,
depending on what the actual code in your program is, is probably the
location of the bug.

I'm going to guess that that line, and the one before it, should
actually be written as:
General a = new Something() as General;

If so, then that's the problem right there. General has a getter, but
no setter. If you were to write the line as,
Server a = new Something() as Server;
then the assignment works fine.

DaTurk wrote:
I have three interfaces, lets call them General, Client, Server.

public interface General
{
public Value{get;}
}

public interface Client : General
{}

public interface Server: General
{
public Value{set;}
}

public class Something : Server, CLient{
}

public class Test{
Something a = new Something();
a as General;
a.Value = 5;
}

THis is essentially what I'm trying to do, but all three interfaces are
in MCPP and for some reason when I try to write to the property Value
it says it can not be accessed. What am I doing wrong? Here is the
actual interface code below, I'll trim out the extraneous methods.

#pragma once

namespace Provider
{

public __gc __interface General : public IDisposable
{

public:
__property NameValueCollection* get_Parameters(void);
};
};

#pragma once

#include "General.h"
namespace Provider
{

public __gc __interface Server : public General
{

public:
__property void set_Parameters(NameValueCollection
*parameters);
};
};

and the CLient, or third interface just adds an additional method. All
I'm trying to do is have the classes that implement server be able to
set properties, and otherwise they can only get them. Thank you in
advance for any help.


Jun 29 '06 #2
HI,

Yeah, I wrote the code on the fly just to give you an idea of what I
was trying to do because the actual classes are quite large. From what
I've found out today, you can't implemetna property like that. I mean,
have one interface with the get, and have an implementing interface
with a set. If you found some way to get that to work in C# I would be
very intrested to see the code. The only reason it works for me is
because the interfaces are in managed c++. Thanks for the response

Jun 29 '06 #3

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

Similar topics

3
by: Joe Delphi | last post by:
Does Visual Basic support multiple inheritance? That is one child class inheriting from more than one parent class. JD
3
by: Tony Johansson | last post by:
Hello experts! I have a small program that is using multiple inheritance. There are 4 classes involved I get 4 compile error that I can't figure out why. It's this row which is located in the...
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...
15
by: jon | last post by:
How can I call a base interface method? class ThirdPartyClass :IDisposable { //I can not modify this class void IDisposable.Dispose() { Console.WriteLine( "ThirdPartyClass Dispose" ); } } ...
29
by: MAHESH MANDHARE | last post by:
Hi , Can Anyone explain me exactly why multiple inheritance not used in java and c# thanks, Mahesh -- Have A Good Day, Mahesh, Maheshmandhare@yahoo.co.in
6
by: David | last post by:
Is there a good workaround the lack of multiple-inheritance? What if some classes expose A's properties and some B's and others expose A's and B's? I have an A class, a B class, an AB class and...
8
by: Tapeesh | last post by:
I have a following piece of code. The code was compiled using g++ class A { public : virtual void fn() = 0; }; class B: virtual private A {
11
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern...
2
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: 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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
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.