In C#, how can I refer to a typedef from a C++/CLI class

screwnut

Given the following c++/cli code:

public ref class A
{
public:
    typedef System::String B;
};

How can I get the following C# code to work:

var b = new A.B();

EDIT: if it helps, the typedef is not a hard requirement. My goal was to end up with a type defined once and usable in both worlds.

Ben Voigt

C# doesn't have typedefs. It does have a form of type aliases made with using declarations, but those don't support your usage (the type alias has to be repeated in every file where it is used, it isn't carried with the containing type).

It's very rare for a language to support consuming a feature from another language, that the first doesn't itself support. And, no surprise, C# doesn't support typedefs declared in C++/CLI any more than it supports typedefs declared in C#.

If you have code that needs this feature, write it in C++/CLI, and call it from C#.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make a shared_ptr from an opaque pointer typedef? (or: how can I "unwrap" typedef?)

From Dev

How to refer to typedef defined in template class

From Dev

How can I clear event subscriptions in C++/CLI?

From Dev

How do I refer to a typedef in a header file?

From Dev

How can i access a class properties from within another one called from a IDataReader Func in C#

From Dev

How can I reference a C# class from a different file?

From Dev

How can I get a list of all methods in a certain class from c++ in mono?

From Dev

How would I write this typedef enum from objective c to swift?

From Dev

How can I refer to a class from another project in the same Workspace in Eclipse/Java

From Dev

Can we have two or more typedef from the same struct in C?

From Dev

How can I call this x86 ASM CALL in C++ with typedef or inline

From Dev

How can I create a Tracker object from my Tracker class in c++?

From Dev

How can I mount /dev from C?

From Dev

How can I get Eclipse CDT to generate a C++ class constructor from data members?

From Dev

How do I return a managed string from a C++/CLI class

From Dev

How do i use typedef in c++ on a function pointer that must return an class template?

From Dev

In C#, how can I refer to a typedef from a C++/CLI class

From Dev

How can I call a method from other Objective-C class?

From Dev

How can I reference a C# class from a different file?

From Dev

In C++ how can I create multiple objects of a class from a file dynamically?

From Dev

How can I refer to the view of a subclass from a superclass in Objective-C?

From Dev

How can I pass value from one subclass to another subclass in a main class C#?

From Dev

How can I mount /dev from C?

From Dev

objective-c : How can I access variables or array from another class?

From Dev

How can I send response from c# class file to MVC Controller

From Dev

C# How can I change textbox.Text from a static method in a separate class and thread

From Dev

C# How can I use an interface to clear a variable value from a different class?

From Dev

How do I use typedef with class initializer parameters in C++?

From Dev

How to typedef a template class with typdef name C++

Related Related

  1. 1

    How can I make a shared_ptr from an opaque pointer typedef? (or: how can I "unwrap" typedef?)

  2. 2

    How to refer to typedef defined in template class

  3. 3

    How can I clear event subscriptions in C++/CLI?

  4. 4

    How do I refer to a typedef in a header file?

  5. 5

    How can i access a class properties from within another one called from a IDataReader Func in C#

  6. 6

    How can I reference a C# class from a different file?

  7. 7

    How can I get a list of all methods in a certain class from c++ in mono?

  8. 8

    How would I write this typedef enum from objective c to swift?

  9. 9

    How can I refer to a class from another project in the same Workspace in Eclipse/Java

  10. 10

    Can we have two or more typedef from the same struct in C?

  11. 11

    How can I call this x86 ASM CALL in C++ with typedef or inline

  12. 12

    How can I create a Tracker object from my Tracker class in c++?

  13. 13

    How can I mount /dev from C?

  14. 14

    How can I get Eclipse CDT to generate a C++ class constructor from data members?

  15. 15

    How do I return a managed string from a C++/CLI class

  16. 16

    How do i use typedef in c++ on a function pointer that must return an class template?

  17. 17

    In C#, how can I refer to a typedef from a C++/CLI class

  18. 18

    How can I call a method from other Objective-C class?

  19. 19

    How can I reference a C# class from a different file?

  20. 20

    In C++ how can I create multiple objects of a class from a file dynamically?

  21. 21

    How can I refer to the view of a subclass from a superclass in Objective-C?

  22. 22

    How can I pass value from one subclass to another subclass in a main class C#?

  23. 23

    How can I mount /dev from C?

  24. 24

    objective-c : How can I access variables or array from another class?

  25. 25

    How can I send response from c# class file to MVC Controller

  26. 26

    C# How can I change textbox.Text from a static method in a separate class and thread

  27. 27

    C# How can I use an interface to clear a variable value from a different class?

  28. 28

    How do I use typedef with class initializer parameters in C++?

  29. 29

    How to typedef a template class with typdef name C++

HotTag

Archive