Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:33:03+00:00 2026-06-04T15:33:03+00:00

I have a couple specific questions regarding mixing managed C++ with unmanaged C++: If

  • 0

I have a couple specific questions regarding mixing managed C++ with unmanaged C++:

  1. If I leave out ref and value in a class/struct declaration, does that automatically make the class/struct unmanaged? Or do I still need to include the #pragma unmanaged and #pragma managed directives?
  2. How compatible are unmanaged and managed types? For example, I can have an unmanaged object in a managed class, right? Can I pass an unmanaged class/struct to a managed function (ie. pass a std::string to a managed function)?

Thanks for your help,

Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:33:05+00:00Added an answer on June 4, 2026 at 3:33 pm

    You can’t have hybrid types (native class containing a managed object, or vice versa). What is possible is to have a pointer to a native class inside a managed one, and a managed handle, wrapped with the gcroot template, inside a native class. This is needed to make sure that the garbage collector never tries to move native data around (which would break pointers held by pure native code).

    Managed types are always implemented using managed code. Native types must be implemented using managed code if they call to managed types.

    #pragma managed(push, off) is the way to force code to be compiled as native. A couple reasons to do this: better optimization from the C++ compiler, can’t be interrupted by garbage collection, etc. Alternatively, you can use /clr:pure to force all code to be compiled as managed, or even /clr:safe to do the same thing and also make it verifiable.

    Any code that is compiled as managed can accept both native and managed types as arguments and return values. And that code can be inside a managed type, native type, or free (global) function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have couple questions regarding some C++ rules. Why am I able to call
I have couple of questions regarding boost licensing, Is it that all the boost
Recently there have been a couple questions regarding static type constraints and inline: Use
In order to stop this being subjective, I have a couple of specific questions
I have a couple of specific questions about font size: Is pt (I.E. 12pt)
I have a couple large arrays that need to be available to a specific
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
Hi I've got a couple of questions regarding associations and how they play in
Currently we have couple projects that are written in Delphi 6. Because of specific
I have a couple of questions. First, i am doing http byte range requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.