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

  • Home
  • SEARCH
  • 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 5841663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:55:07+00:00 2026-05-22T11:55:07+00:00

If I define a new ref class in C++/CLI, can I then use this

  • 0

If I define a new ref class in C++/CLI, can I then use this type as a standard unmanaged class, and if so, does the ref keyword alter the memory layout of the datatype at all?

In my case, there is a class which is used all over the place in a very very large C++ application. We’ll call it MyExampleThing:

class MyExampleThing
{
    int a = 0;
    int b = 1;
}

We’re looking at the possibility of slowly integrating more .net framework components into this application through C++/CLI. If I port this class to a ref class would it (under normal circumstances) continue to work in other plain old unmanaged C++ code? Or would I have to leave it as is and write a ref class wrapper to handle .net interop?

To be clear: I know I can’t just pass an unmanaged pointer into managed code, I’m just asking if I can use the class separately as either managed or unmanaged.

Is the same true for value class?

Also important: If I can create ref classes on the unmanaged heap, is the memory layout the same as if it were a regular C++ class? (The unmanaged versions of this class get serialized byte for byte as binary data. Yes, I’m aware of endianness issues of doing it that way, no I didn’t make that decision.)

  • 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-05-22T11:55:08+00:00Added an answer on May 22, 2026 at 11:55 am

    ref is not a keyword I’m familiar with so I’m going to go out on a limb and say it’s probably not supported by unmanaged C++

    If you have reusable classes for a library I would just make them in unmanaged C++ which can easily be imported and used by managed code and keep your .NET components and managed code separated. Prefer decoupled classes and interfaces over objects that do a little bit of everything whenever you can.

    You can also make wrappers which marshal between managed and unmanaged code when you do need to have one side communicate with the other. My experience is limited to having a C# application calling into a C++ library I experimented with CLI at one point but didn’t find it particularly useful myself.

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

Sidebar

Related Questions

I need to define new UI Elements as well as data binding in code
I often want to define new 'Exception' classes, but need to have an appropriate
Particularly, what is the best snippets package out there? Features: easy to define new
Since Rails 2.1, if you define a new column in a migration with the
Hej All I have some code that builds a new TYPE runtime, it sets
Any ideas as to why this public Collection<Point> data = new Collection<Point>(){ new Point{X=10,Y=20},
Why this can't compile: // RefToPointers.cpp : Defines the entry point for the console
I am developing a schema using RELAX NG. I'm pretty new to this, so
I've overridden new so that I can track memory allocations. Additional parameters such as
I have defined a new dialog and its controls in an already existing resource

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.