Multiple Inheritance w/ Managed C++, how can you access an implementing classes properties after cas

D

DaTurk

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.
 
J

james.curran

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.
 
D

DaTurk

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top