Thread: IntPtr

  1. #1
    Registered User
    Join Date
    Feb 2018
    Posts
    24

    IntPtr

    Code:
    using namespace std;
    #include <cstring>
    #include <iostream>
    #include <cstdlib>
    
    
    int main(){
        IntPtr p;
    }
    hello all
    in the book it says it is legal to create a pointer with "IntPtr" but in this code it gave me error ? anybodey help me ?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by uryenugurkem
    in the book
    I presume that by "the book" you mean Jumping into C++, which happens to have been authored by the webmaster of this website and forum community. As such, I shall move this topic to the C++ programming forum.

    Quote Originally Posted by uryenugurkem
    it says it is legal to create a pointer with "IntPtr" but in this code it gave me error ? anybodey help me ?
    It is legal to do so if you have a typedef for the name IntPtr. Without such a typedef, the name IntPtr is undefined, so you would be unable to do so.

    By the way, the using namespace std; using directive should be placed after the last header inclusion. Placing it before a header inclusion affects the content of the header, which can be a Bad Thing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Guest
    Guest
    I don't think a type IntPtr is defined in the headers you included, so the compiler doesn't know about it.

    There might be a custom header supplied with the book you're using that defines this type.

    If you include cstdint, you could use intptr_t but I think you should stick to declaring pointers the usual way unless you have a specific reason.

    (laserlight beat me to it, I'll just leave my reply )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IntPtr to byte[] without copy
    By Elkvis in forum C# Programming
    Replies: 4
    Last Post: 04-19-2012, 06:54 AM
  2. Replies: 11
    Last Post: 07-14-2010, 11:13 PM
  3. Marshall HWND to IntPtr
    By Opariti in forum Windows Programming
    Replies: 0
    Last Post: 12-17-2008, 08:32 AM
  4. IntPtr
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-19-2008, 06:18 AM
  5. Byte array to IntPtr : Safely
    By PaulStat in forum C# Programming
    Replies: 0
    Last Post: 08-12-2003, 10:17 AM

Tags for this Thread