reference has a rule of reference.

This is a discussion on reference has a rule of reference. within the C++ Programming forums, part of the General Programming Boards category; Howdy. when I practise something about reference I figure out we could not declare a reference with more than 1 ...

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Arrow reference has a rule of reference.

    Howdy.

    when I practise something about reference I figure out we could not declare a reference with more than 1 line, otherwise we would get an error.

    we could:
    PHP Code:
    int r;
    int ref=r
    but we couldnt:
    PHP Code:
    int r;
    int ref;
    ref=r
    Because I know not much about reference and something relatively, so, anyone would give some information about others which are suitable for this rule ?
    thanx in advance~
    Never end on learning~

  2. #2
    Registered User snowy101's Avatar
    Join Date
    May 2002
    Posts
    22

    ok here goes

    basicly what your telling the computer with the 2nd php is that and integar will be stored in r and then the 2nd line says int and ref and thats it doesn't equal anything or tell it what to do it just tells the computer that int and ref ..... and then it gets confused and crashes thats why it doesn't work.

    and if it works on the first php then use it. i remember this phrase if it isn't broken dont fix it. =) just use the first one unless it messes up something else in your program

    best of luck (snowy)
    Simple Programming

    :::: Error Message != A Smile ::::

  3. #3
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    ~

    Originally posted by snowy101
    basicly what your telling the computer with the 2nd php is that and integar will be stored in r and then the 2nd line says int and ref and thats it doesn't equal anything or tell it what to do it just tells the computer that int and ref ..... and then it gets confused and crashes thats why it doesn't work.

    and if it works on the first php then use it. i remember this phrase if it isn't broken dont fix it. =) just use the first one unless it messes up something else in your program

    best of luck (snowy)
    thanx, Snowy~

    and what about others such as pointer ? is this rule convenient for them then ?
    Never end on learning~

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    References must be initialized where they are declared because they are always valid. While a pointer can point to nothing (IE, NULL or 0), a reference always refers to an object.

    If you try to declare a reference to nothing, like in your code, you get an error, because a reference always must reference something.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  5. #5
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Lightbulb

    Originally posted by SilentStrike
    References must be initialized where they are declared because they are always valid. While a pointer can point to nothing (IE, NULL or 0), a reference always refers to an object.

    If you try to declare a reference to nothing, like in your code, you get an error, because a reference always must reference something.
    got it ! thanx~
    Never end on learning~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 05:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21