Interface stuff does not compile

S

solved by design

Hi all!

I have this clases:

interface class i1

{

void m(void);

void m2(void);

};

interface class i2

{

//void m(void);

void m3(void);

};

ref class pepe:public i1,public i2

{

virtual void m(void){;}

virtual void m2(void){;}

virtual void m3(void){;}

};

Visual Studio says me that I've to implement each virtual method for all
interfaces into my pepe class, but that is the thing that I'm doing.

Can someone tell me where's my error? Working with C++/CLI, of course.

Thanks in advance.
 
B

Bruno van Dooren

Hi all!
I have this clases:

interface class i1

{

void m(void);

void m2(void);

};

interface class i2

{

//void m(void);

void m3(void);

};

ref class pepe:public i1,public i2

{

put 'public:' here and it compiles without a problem.
members are private by default in a ref class.
i think private is not what you want anyway?
otherwise you would not have used 'virtual' probably.

I think interface members have to be implemented as public.
otherwise they won't make much sense.
see here for references:
http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=365736
virtual void m(void){;}

virtual void m2(void){;}

virtual void m3(void){;}

};

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
T

Tamas Demjen

solved said:
ref class pepe:public i1,public i2

{

virtual void m(void){;}

virtual void m2(void){;}

virtual void m3(void){;}

};

The problem here is that your methods in "pepe" are private and virtual,
which doesn't work in .NET. In an interface class the default access
type is public. In a ref class it's private. You should put the line
"public:" before your methods, and it will compile fine, or declare
"pepe" a ref struct instead of a ref class.

If you absolutely want to make those methods private, and you're sure
what you're doing, just seal the class or all three methods.

Tom
 
M

Marcus Heege

In addition to the public implementation that Bruno and Tamas have
mentioned, you can also provide a private implementation. The code below
compiles even though the methods implementing the interface are private:

interface class i1

{

void m(void);

void m2(void);

};

interface class i2

{

//void m(void);

void m3(void);

};

ref class pepe:public i1,public i2

{

virtual void m(void) sealed = i1::m {;}

virtual void m2(void) sealed = i1::m2 {;}

virtual void m3(void) sealed = i2::m3 {;}

};
 
S

solved by design

Oh, thank you. I's very interesting.

Then, the way to uncomment second "void m(void)" is to rename virtual
method, because

public:
virtual void i2::m() {}

does not work.

It could be:

public:
virtual void newMethod() = i2::m ()

With or without sealing it.

I'm in love with C++. :)
 

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