Thread: How to convert integral types into pointer types?

  1. #1
    Registered User
    Join Date
    Mar 2008

    How to convert integral types into pointer types?

    Hi All,

    Can anyone please tell how to convert integral types like Integer into pointer types like Integer& ? (if we say Integer is a class).

    This question has originated from following thread:




  2. #2
    Registered User
    Join Date
    Jun 2005
    Quote Originally Posted by rohit99 View Post
    Yeah, right, that really deserves a quick response.

    Rules of the language mean that the name of a variable is inherently a reference to it if a reference is required: the conversion is implicit.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    Integer& is a reference and not a pointer type.
    To pass by reference, all you need to do is append & after the type in the receiving function and then pass the argument like normal. A reference is part of the type, so while originally "type", it becomes "type&" when you declare it as a reference.

    void foo(int& n) { }
    int main() { int n = 0; foo(n); return 0; }
    Adding const only means that the receiving function cannot modify the variable. Nothing else. It's still passed by reference.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Hi grumpy and Elysia,

    Thanks for your replies.. I thnk I am sounding quite funny.. I knw Integer will b implicitly converted into Integer&.. n I didn't care about this while writing code bt I faced sum issues.. I guess not because of I panicked n thought issues were due to that conversion as compiler threw sum error sumwat similar to that..... I am sorry....


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. convert reference to pointer?
    By Marksman in forum C++ Programming
    Replies: 4
    Last Post: 10-08-2008, 05:32 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  3. incompatible pointer types
    By quasigreat in forum C Programming
    Replies: 4
    Last Post: 05-22-2008, 12:30 AM
  4. Pointer types
    By jrfall349 in forum C Programming
    Replies: 8
    Last Post: 04-23-2007, 10:58 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM