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. C / C++ / MFC
  4. simple c++ question???

simple c++ question???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++tutorial
5 Posts 2 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.
  • J Offline
    J Offline
    John Cruz
    wrote on last edited by
    #1

    do anyone know how to write a copy of a pointer where the copy cant change what the original pointer is pointing to kinda like using call by value or call by constant reference but using pointers. i am having trouble doing this because if i make it constant, I cant change it, i can use reference but because the whole program is implemented with pointers i wont be able to use it. do anyone know how to get around this problem??? ex. int CComputer::CheckForMove(const CBoard* pBoard, int depth) but by doing this i cant call most of the function that would change the board because that would give me a syntax error... i wanted to used CheckForMove(const CBoard& rBoard, int depth) but i wont be able to use it because my whole program is done using pointers... anyways, thank you for your help... :)

    C 1 Reply Last reply
    0
    • J John Cruz

      do anyone know how to write a copy of a pointer where the copy cant change what the original pointer is pointing to kinda like using call by value or call by constant reference but using pointers. i am having trouble doing this because if i make it constant, I cant change it, i can use reference but because the whole program is implemented with pointers i wont be able to use it. do anyone know how to get around this problem??? ex. int CComputer::CheckForMove(const CBoard* pBoard, int depth) but by doing this i cant call most of the function that would change the board because that would give me a syntax error... i wanted to used CheckForMove(const CBoard& rBoard, int depth) but i wont be able to use it because my whole program is done using pointers... anyways, thank you for your help... :)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I *believe* the syntax is int * const pConstInt; Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little.

      J 1 Reply Last reply
      0
      • C Christian Graus

        I *believe* the syntax is int * const pConstInt; Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little.

        J Offline
        J Offline
        John Cruz
        wrote on last edited by
        #3

        yah your right but is there way i can use pointer and not use reference to do my function... hey, christian thankx for the help :) :)

        C 1 Reply Last reply
        0
        • J John Cruz

          yah your right but is there way i can use pointer and not use reference to do my function... hey, christian thankx for the help :) :)

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I don't understand ? If I do this: int * const pInt = new int; I can do this with no problems: *pInt = 5; because the value is not const. I cannot do this: pInt = new int; because the pointer *is*. Isn't that what you wanted ? Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little.

          J 1 Reply Last reply
          0
          • C Christian Graus

            I don't understand ? If I do this: int * const pInt = new int; I can do this with no problems: *pInt = 5; because the value is not const. I cannot do this: pInt = new int; because the pointer *is*. Isn't that what you wanted ? Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little.

            J Offline
            J Offline
            John Cruz
            wrote on last edited by
            #5

            ok ill try that... thanks :)

            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