Inherit an interface in managed C++

G

Guest

I'm trying to make a class that already inherits from a base class, also
inherit from an interface in managed C++.

so my interface looks like so:

__gc interface ITask
{
__property String* get_Subject();
};

and the class that inherits from it is defined like so:

public __gc class Message : public MsgObject, public ITask {

and the get_Subject property in the header file for Message looks like so:

__property String* get_Subject();

but no matter what i try, i cant get it to compile. I've played with every
combination of __gc, interface, __interface, public or not and no luck.

mostly i get a compile error stating that my Message class can only inherit
from one base class. but i've got the ITask defined as an interface. any
ideas?

thanks.
 
G

Guest

ok...so i figured out i was miss-defining my interface. the following works
just fine:

public __gc __interface ITask
{
public public:
__property String* get_Subject();
__property String* get_Text();
};

I was basically missing the "public public", which leads me to my next
question: What in the heck does "public public" mean. Its doubly public. is
"public public public" even more public? ;-)

seriouslyl though...what is the double public thing for?
 
P

Peter Oliphant

I think your problem is (and I'm having the same problem with my code) is
that MANAGED code doesn't allow MULTIPLE-inheritance.

So:

public __gc class Message : public MsgObject, public ITask ...

just won't work... (sorry, I wish it did, would save me lots of extra work
too...hehe)
 
G

Guest

It doesnt allow multiple class inheritance, but you can inherit from as many
interfaces as you want. I figured out the problem, i just cant find any info
 
R

Ronald Laeremans [MSFT]

john said:
ok...so i figured out i was miss-defining my interface. the following works
just fine:

public __gc __interface ITask
{
public public:
__property String* get_Subject();
__property String* get_Text();
};

I was basically missing the "public public", which leads me to my next
question: What in the heck does "public public" mean. Its doubly public. is
"public public public" even more public? ;-)

seriouslyl though...what is the double public thing for?



:
It should work with just one "public" there.

public public:
is a synonym for
public:

If you use 2 then the most restrictive one is for access outside the
assembly and the least restrictive one is for access inside the assembly.

E.g.

public private:

Means that any class in the assembly can access the members defiend
after this but no class outside of the assembly can.

Ronald
 
G

Guest

Eurika!!!

thanks dude

Ronald Laeremans said:
It should work with just one "public" there.

public public:
is a synonym for
public:

If you use 2 then the most restrictive one is for access outside the
assembly and the least restrictive one is for access inside the assembly.

E.g.

public private:

Means that any class in the assembly can access the members defiend
after this but no class outside of the assembly can.

Ronald
 

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