from c++ to c++/cli

Z

zs

Hi!

I have a question about converting from native c++ to c++/cli.
How to convert/rewrite c++ code that looks like this to cli:

//MyC.h

namespace MyNS
{
MyClass
{
public:
void F();
};

}

//MyC.cpp

#include "MyC.h"

namspace MyNS
{
MyClass::F(){....}

}

And second question is, are "using namespace" statements
in header files not recomended also in cli or ...?

Thx!

Best regards,
Zoran Stipanicev
 
J

Jochen Kalmbach [MVP]

Hi zs!
I have a question about converting from native c++ to c++/cli.
How to convert/rewrite c++ code that looks like this to cli:

[snip]

What do you want to rewrite? Just compile...

Or do you need to expose those classes to other managed assemblies?

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Z

zs

I have to rewrite matrix class from native c++ to .NET. I have to
implement expresion templates with generics (or just try to do it).
It's for faculty.
And I have to compare execution time for native c++ and .NET solution.
 
Z

zs

I forgot to mention, I've tried with creating new CLR console app and
'copy paste' code but it doesn't compile. I'v
 
Z

zs

I forgot to mention, I've tried with creating new CLR console app and
'copy paste' code but it doesn't compile. I've changed native classes
to .NET classes (ofstream -> filestream and binarywriter).
 
P

Peter Oliphant

First, you need to fix the code you already have. I bet the code you list
doesn't compile at all, since the line that says just 'MyClass' needs to say
'class MyClass'. I noticed this since what you need to do to change the code
to CLI code is to change 'class MyClass' to 'ref class MyClass'. Also, not
sure about this, but namespaces might need to be terminated by a semi-colon
( ; ) like classes do. Further, 'namespace' needs to be correctly spelled,
'namspace' just won't do... ; )

I think you using namespaces in headers is just fine. In fact, I try to
write all my code in classes defined in headers (and rarely use my own
namespaces), but that's a matter of taste, style, and requirements...

[==P==]
 
M

Marcus Kwok

Peter Oliphant said:
I think you using namespaces in headers is just fine. In fact, I try to
write all my code in classes defined in headers (and rarely use my own
namespaces), but that's a matter of taste, style, and requirements...

I think zs was talking about using-directives in header files. I am a
CLI newbie, but I would imagine the same recommendation of not putting
using-directives in header files would apply, since the same issues with
name collision can occur in either language.
 

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