Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. [Connect bug] VC++ 2010 : C++/CLI does not support variant delegates/interfaces

[Connect bug] VC++ 2010 : C++/CLI does not support variant delegates/interfaces

Scheduled Pinned Locked Moved The Lounge
helpcsharpwpfcomc++
28 Posts 14 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1
    • Link to Connect bug[^]

    I posted that a day back. If any of you do use C++/CLI and this is an issue that you think is serious enough to require quick resolution, please vote the issue up. A higher number of votes will help them prioritize on the time/resources they want to spend on this issue. Thank you. To summarize, C++/CLI has not been updated to support variance in delegates and interfaces. C# 4.0 supports this and this limitation in C++/CLI will bring down its utility as an interop language. The following code does not compile in C++/CLI today, though the equivalent C# code will compile.

    ref class Base {};

    ref class Derived : Base {};

    int main(array<System::String ^> ^args)
    {
    return 0;
    }

    void FooInterfaces()
    {
    IEnumerable<Base^>^ base = gcnew List<Base^>();
    IEnumerable<Derived^>^ derived = gcnew List<Derived^>();
    base = derived; // <-- Error C2440 here
    // IEnumerable<> is covariant so this should compile and does so in C# 4.0
    }

    generic<typename T> void ShowItem (T item, Action<T>^ showFunc)
    {
    showFunc(item);
    }

    void ShowBase(Base^ b) { }

    void FooDelegates()
    {
    Derived^ d = gcnew Derived();
    ShowItem<Derived^>(d, gcnew Action<Derived^>(ShowBase)); // <-- Error C3352 here
    // Action<> is contravariant and this compiles in C# 4.0
    }

    Thank you.

    Regards, Nish


    Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

    J R 2 Replies Last reply
    0
    • N Nish Nishant
      • Link to Connect bug[^]

      I posted that a day back. If any of you do use C++/CLI and this is an issue that you think is serious enough to require quick resolution, please vote the issue up. A higher number of votes will help them prioritize on the time/resources they want to spend on this issue. Thank you. To summarize, C++/CLI has not been updated to support variance in delegates and interfaces. C# 4.0 supports this and this limitation in C++/CLI will bring down its utility as an interop language. The following code does not compile in C++/CLI today, though the equivalent C# code will compile.

      ref class Base {};

      ref class Derived : Base {};

      int main(array<System::String ^> ^args)
      {
      return 0;
      }

      void FooInterfaces()
      {
      IEnumerable<Base^>^ base = gcnew List<Base^>();
      IEnumerable<Derived^>^ derived = gcnew List<Derived^>();
      base = derived; // <-- Error C2440 here
      // IEnumerable<> is covariant so this should compile and does so in C# 4.0
      }

      generic<typename T> void ShowItem (T item, Action<T>^ showFunc)
      {
      showFunc(item);
      }

      void ShowBase(Base^ b) { }

      void FooDelegates()
      {
      Derived^ d = gcnew Derived();
      ShowItem<Derived^>(d, gcnew Action<Derived^>(ShowBase)); // <-- Error C3352 here
      // Action<> is contravariant and this compiles in C# 4.0
      }

      Thank you.

      Regards, Nish


      Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

      J Offline
      J Offline
      Joe Woodbury
      wrote on last edited by
      #2

      Looks like the other five users of C++/CLI have already voted with you.

      N N 2 Replies Last reply
      0
      • J Joe Woodbury

        Looks like the other five users of C++/CLI have already voted with you.

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Damn you! :-D

        Regards, Nish


        Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

        1 Reply Last reply
        0
        • J Joe Woodbury

          Looks like the other five users of C++/CLI have already voted with you.

          N Offline
          N Offline
          Nemanja Trifunovic
          wrote on last edited by
          #4

          Joe Woodbury wrote:

          Looks like the other five users of C++/CLI have already voted with you.

          :D I love this kind of jokes, but C++/CLI is actually used (if not liked) by many more people than one would expect. Many people are falling in trap of "reusing the legacy C/C++ code while leveraging the productivity gains of .NET platform".

          utf8-cpp

          J 1 Reply Last reply
          0
          • N Nemanja Trifunovic

            Joe Woodbury wrote:

            Looks like the other five users of C++/CLI have already voted with you.

            :D I love this kind of jokes, but C++/CLI is actually used (if not liked) by many more people than one would expect. Many people are falling in trap of "reusing the legacy C/C++ code while leveraging the productivity gains of .NET platform".

            utf8-cpp

            J Offline
            J Offline
            Joe Woodbury
            wrote on last edited by
            #5

            Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

            R E M S L 7 Replies Last reply
            0
            • J Joe Woodbury

              Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

              R Offline
              R Offline
              Rob Graham
              wrote on last edited by
              #6

              I've found it very useful for interop between Managed (C#,etc.) and legacy unmanaged C++ code. It's much more efficient than COM interop, and more flexible than pInvoke for scenarios where COM interop is not a choice). I would not use it for anything more significant than a thin interop layer, however.

              S R 2 Replies Last reply
              0
              • J Joe Woodbury

                Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

                E Offline
                E Offline
                El Corazon
                wrote on last edited by
                #7

                Joe Woodbury wrote:

                (If you've written C++/CLI, that makes three.)

                I have.

                _________________________ John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others." Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....

                1 Reply Last reply
                0
                • J Joe Woodbury

                  Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

                  M Offline
                  M Offline
                  Matt Gullett
                  wrote on last edited by
                  #8

                  I've used it a little, though to be honest, I mostly try and skip .NET altogether and stick with C++ for most of my needs.

                  E J 2 Replies Last reply
                  0
                  • M Matt Gullett

                    I've used it a little, though to be honest, I mostly try and skip .NET altogether and stick with C++ for most of my needs.

                    E Offline
                    E Offline
                    El Corazon
                    wrote on last edited by
                    #9

                    Matt Gullett wrote:

                    I've used it a little, though to be honest, I mostly try and skip .NET altogether and stick with C++ for most of my needs.

                    you and me both. :-D

                    _________________________ John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others." Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....

                    1 Reply Last reply
                    0
                    • J Joe Woodbury

                      Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

                      S Offline
                      S Offline
                      Shog9 0
                      wrote on last edited by
                      #10

                      Well, yeah... It's easily the worst-supported (official) .NET language out there, so it doesn't get talked about much. At this point, I'm not interested in doing major work in a language that MS apparently wishes would die... But, it beats P/Invoke, so in the boundary between the C++ app and .NET components it has a home.

                      1 Reply Last reply
                      0
                      • M Matt Gullett

                        I've used it a little, though to be honest, I mostly try and skip .NET altogether and stick with C++ for most of my needs.

                        J Offline
                        J Offline
                        Joe Woodbury
                        wrote on last edited by
                        #11

                        I also work mostly in C++. I do maintain a .NET library that interfaces with our core DLLs (with C entry points.) (For our XP embedded based system, I deliberately tried to write two utilities in .NET and abandoned the effort due to lack of support in the framework for what I needed to do. On top of that, the .NET version for one utility was over 10x bigger than the native version [and it wasn't even done!] and when pushing updates over cell that's a very big deal. One key utility was done in .NET and sometimes I want to strangle the guy who did that.)

                        1 Reply Last reply
                        0
                        • R Rob Graham

                          I've found it very useful for interop between Managed (C#,etc.) and legacy unmanaged C++ code. It's much more efficient than COM interop, and more flexible than pInvoke for scenarios where COM interop is not a choice). I would not use it for anything more significant than a thin interop layer, however.

                          S Offline
                          S Offline
                          Single Step Debugger
                          wrote on last edited by
                          #12

                          We are also using it like a middle tier when extending a MFC application with C#.

                          The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                          1 Reply Last reply
                          0
                          • N Nish Nishant
                            • Link to Connect bug[^]

                            I posted that a day back. If any of you do use C++/CLI and this is an issue that you think is serious enough to require quick resolution, please vote the issue up. A higher number of votes will help them prioritize on the time/resources they want to spend on this issue. Thank you. To summarize, C++/CLI has not been updated to support variance in delegates and interfaces. C# 4.0 supports this and this limitation in C++/CLI will bring down its utility as an interop language. The following code does not compile in C++/CLI today, though the equivalent C# code will compile.

                            ref class Base {};

                            ref class Derived : Base {};

                            int main(array<System::String ^> ^args)
                            {
                            return 0;
                            }

                            void FooInterfaces()
                            {
                            IEnumerable<Base^>^ base = gcnew List<Base^>();
                            IEnumerable<Derived^>^ derived = gcnew List<Derived^>();
                            base = derived; // <-- Error C2440 here
                            // IEnumerable<> is covariant so this should compile and does so in C# 4.0
                            }

                            generic<typename T> void ShowItem (T item, Action<T>^ showFunc)
                            {
                            showFunc(item);
                            }

                            void ShowBase(Base^ b) { }

                            void FooDelegates()
                            {
                            Derived^ d = gcnew Derived();
                            ShowItem<Derived^>(d, gcnew Action<Derived^>(ShowBase)); // <-- Error C3352 here
                            // Action<> is contravariant and this compiles in C# 4.0
                            }

                            Thank you.

                            Regards, Nish


                            Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

                            R Offline
                            R Offline
                            Rajesh R Subramanian
                            wrote on last edited by
                            #13

                            I've voted there (I'm not using c++/cli though).

                            It's time for a new sig. Seriously.

                            N D 2 Replies Last reply
                            0
                            • R Rajesh R Subramanian

                              I've voted there (I'm not using c++/cli though).

                              It's time for a new sig. Seriously.

                              N Offline
                              N Offline
                              Nish Nishant
                              wrote on last edited by
                              #14

                              Thank you :thumbsup:

                              Regards, Nish


                              Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

                              S 1 Reply Last reply
                              0
                              • J Joe Woodbury

                                Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                Joe Woodbury wrote:

                                Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

                                I used it for a project. I had a c++ core library to talk to a data source and then a code generator that made c++ and c++/cli classes to encode / decode different protocols. That code was then used to build c++ and c# clients of the data source. The main advantage was the core c++ library was reused by the c# clients as it was statically linked to the cli code library. It was even used on linux with mono.

                                1 Reply Last reply
                                0
                                • N Nish Nishant

                                  Thank you :thumbsup:

                                  Regards, Nish


                                  Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

                                  S Offline
                                  S Offline
                                  Single Step Debugger
                                  wrote on last edited by
                                  #16

                                  For not using it? Why, is it the CLI in low supply these days? :-D

                                  The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                                  N 1 Reply Last reply
                                  0
                                  • S Single Step Debugger

                                    For not using it? Why, is it the CLI in low supply these days? :-D

                                    The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                                    N Offline
                                    N Offline
                                    Nish Nishant
                                    wrote on last edited by
                                    #17

                                    Deyan Georgiev wrote:

                                    For not using it? Why, is it the CLI in low supply these days?

                                    Yeah big joke, funny guy! :rolleyes:

                                    Regards, Nish


                                    Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application

                                    S 1 Reply Last reply
                                    0
                                    • R Rajesh R Subramanian

                                      I've voted there (I'm not using c++/cli though).

                                      It's time for a new sig. Seriously.

                                      D Offline
                                      D Offline
                                      Dan Neely
                                      wrote on last edited by
                                      #18

                                      Rajesh R Subramanian wrote:

                                      I've voted there

                                      It's kinda sad how few people here did the same. It's only at 9 votes now and was 4 before I cast mine. The entire point of posting connect bug reports here is the I'll Scratch Your Back If You Scratch Mine Principle. It all falls apart if we don't vote each other's bugs to the TEOTWAWKI level necessary to have MS patch them in the next major release.

                                      3x12=36 2x12=24 1x12=12 0x12=18

                                      J N 2 Replies Last reply
                                      0
                                      • J Joe Woodbury

                                        Other than Nish, here on CP, and myself, I don't know a soul who has written any C++/CLI code, even to try it out. I've written some C++/CLI code, just to see what it could do. Wasn't impressed and found the lack of interest by Microsoft to document and help you along to be a major show stopper. (If you've written C++/CLI, that makes three.)

                                        P Offline
                                        P Offline
                                        Phil Martin
                                        wrote on last edited by
                                        #19

                                        /me puts his hand up. I've used it to expose .Net objects in Tcl, i.e. .Net Tcl extensions plus things that look like object. It astonished me just what a piece of engineering C++/CLI was. I couldn't believe it all worked as advertised. Typing with a baby in one hand is slow.

                                        J 1 Reply Last reply
                                        0
                                        • P Phil Martin

                                          /me puts his hand up. I've used it to expose .Net objects in Tcl, i.e. .Net Tcl extensions plus things that look like object. It astonished me just what a piece of engineering C++/CLI was. I couldn't believe it all worked as advertised. Typing with a baby in one hand is slow.

                                          J Offline
                                          J Offline
                                          Joe Woodbury
                                          wrote on last edited by
                                          #20

                                          Phil Martin... wrote:

                                          Typing with a baby in one hand is slow.

                                          Typing while holding a toddler who thinks keyboards are great fun is ever slower.

                                          P 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups