7 Replies - 6237 Views - Last Post: 15 October 2011 - 06:52 AM

#1 Mennovf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-October 11

std::string in managed code

Posted 14 October 2011 - 01:48 PM

Is it possible to declare an std::string as a member class of managed class. My compiler gives me error:C4368: cannot define"myClass" as a member of managed "myClass2": mixed types are not supported.

It seems that other people are not having issues with this, how can I implement an std::string in managed C++?
Is This A Good Question/Topic? 0
  • +

Replies To: std::string in managed code

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1623
  • View blog
  • Posts: 5,710
  • Joined: 03-August 09

Re: std::string in managed code

Posted 14 October 2011 - 02:37 PM

err... is this CLI C++? if not, please post the code and exact error message, otherwise we have a different forum for CLI C++
Was This Post Helpful? 0
  • +
  • -

#3 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: std::string in managed code

Posted 14 October 2011 - 08:49 PM

Your question deeply confuses me. Are you trying to define a class with a type? Because class IS a type. You can define strings inside of classes, yes.

Can you elaborate on your issue in any way at all?
Was This Post Helpful? 0
  • +
  • -

#4 Mennovf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-October 11

Re: std::string in managed code

Posted 15 October 2011 - 02:49 AM

Sure I can, I have defined a managed class(ref class myClass{};) with a member that is an std::string and some functions that need an std::string (also a complex number from the <complex> header) as a paramter or return one. But when I try to build this, it gives me an error saying that mixed types aren't supported. This is quite annoying as it is the only thing I need fixed/changed to actually test my code.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: std::string in managed code

Posted 15 October 2011 - 04:34 AM

Moved to CLI C++
Was This Post Helpful? 0
  • +
  • -

#6 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5931
  • View blog
  • Posts: 12,853
  • Joined: 16-October 07

Re: std::string in managed code

Posted 15 October 2011 - 04:43 AM

What does std::string offer that String^ can't? Simply, if you've chosen to go C++.NET, you should be using those tools. If you're trying to wedge legacy C++ code in .NET, you'd be better off creating a DLL and wrapping it.
Was This Post Helpful? 0
  • +
  • -

#7 Mennovf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 09-October 11

Re: std::string in managed code

Posted 15 October 2011 - 05:04 AM

You're probably right, it's just that I was just getting used to coding in C++ nad then I found out there was a whole diffrent section of C++ I didn't know about and which I need to know about for using Windows Forms. I wrote my code before finding out that I had to convert it to managed code, it would've been so much easier if I didn't had to change this part.
But my main concern then is the std::complex, does managed code offer something similar or how can I implement this?
Was This Post Helpful? 0
  • +
  • -

#8 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5931
  • View blog
  • Posts: 12,853
  • Joined: 16-October 07

Re: std::string in managed code

Posted 15 October 2011 - 06:52 AM

I don't see anything standard for std::complex in .NET. Here's a guy who did a wrapper: http://www.codeproje...mplex_math.aspx

It's an entertaining project and no reason you couldn't roll you own in just .NET. There's bound to be more out there.

If you're using .NET, I'd avoid C++.NET. It's an ugly bastardization C++ and because of the architecture gains you nothing over C# or VB.NET. Also, the Visual Studio tools for it are some of the worst in the suite. It exists as a bridge, but I sure wouldn't want to do GUI development in it.

If you have C++ code you need in .NET, port it to C++.NET if you can or wrap it. If you're doing .NET Forms programming from the ground up, avoid it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1