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. General Programming
  3. Managed C++/CLI
  4. Do I have to use pointers only?

Do I have to use pointers only?

Scheduled Pinned Locked Moved Managed C++/CLI
c++csharpquestion
6 Posts 2 Posters 19 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.
  • A Offline
    A Offline
    Alexandru Savescu
    wrote on last edited by
    #1

    Hi! I just my first semi-project in .NET that combines both MFC and MC++ and it works fine! However, when I needed to use any .NET classes I had to declare them as pointers and pass pointers to methods etc., like this

    SqlConnection* s = new SqlConnection();
    f (s);

    Is this the only way it works? :confused: Apparently yes, and I feel sad, I've been using C++ for a while and got used to using references and not pointers.... :rose: Best regards, Alexandru Savescu

    N 1 Reply Last reply
    0
    • A Alexandru Savescu

      Hi! I just my first semi-project in .NET that combines both MFC and MC++ and it works fine! However, when I needed to use any .NET classes I had to declare them as pointers and pass pointers to methods etc., like this

      SqlConnection* s = new SqlConnection();
      f (s);

      Is this the only way it works? :confused: Apparently yes, and I feel sad, I've been using C++ for a while and got used to using references and not pointers.... :rose: Best regards, Alexandru Savescu

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

      You'll have to create all reference types on the heap. Thus you cannot have a String but only a String*. On the other hand you can have value types on the stack. Nish


      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

      A 1 Reply Last reply
      0
      • N Nish Nishant

        You'll have to create all reference types on the heap. Thus you cannot have a String but only a String*. On the other hand you can have value types on the stack. Nish


        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

        A Offline
        A Offline
        Alexandru Savescu
        wrote on last edited by
        #3

        Thanks Nish, but could you please provide me with some examples with those differences? Thanks. Best regards, Alexandru Savescu

        N 1 Reply Last reply
        0
        • A Alexandru Savescu

          Thanks Nish, but could you please provide me with some examples with those differences? Thanks. Best regards, Alexandru Savescu

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

          ****Alexpro wrote: Thanks Nish, but could you please provide me with some examples with those differences?

          //String has to be on the heap
          //It's an __gc class
          String *s = new String("hey there");

          //Point is a value type
          Point p = Point(10,19);


          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

          A 1 Reply Last reply
          0
          • N Nish Nishant

            ****Alexpro wrote: Thanks Nish, but could you please provide me with some examples with those differences?

            //String has to be on the heap
            //It's an __gc class
            String *s = new String("hey there");

            //Point is a value type
            Point p = Point(10,19);


            Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

            A Offline
            A Offline
            Alexandru Savescu
            wrote on last edited by
            #5

            Thanks! I better lookup in the documentation to see the difference between refernce types and value types! :~ Best regards, Alexandru Savescu

            N 1 Reply Last reply
            0
            • A Alexandru Savescu

              Thanks! I better lookup in the documentation to see the difference between refernce types and value types! :~ Best regards, Alexandru Savescu

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

              ****Alexpro wrote: Thanks! I better lookup in the documentation to see the difference between refernce types and value types! Have fun :-) Nish


              Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

              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