Thread: References

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    1

    References

    Code:
    class fred
      {
         char           * Buf;
         char const *& ConstBuf;
    
        fred ( void );
    
      };
    
    fred::fred(void)
    :
    Buf ( 0 ),
    ConstBuf ( Buf)
    {
    }
    ,
    [Text]
    1. Buffer and ConstBuf will refer to the same data storage area. ConstBuf read-only and Buffer read-write.
    2. I want the more restricted ConstBuf to refer to Buf. and declared in a class.
    3 Question: how do I initialize the reference? The compiler complains if I attempt to do so within a class, and it complains when I try to do so in a constructor.
    [Text]

    T

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by KPM
    2. I want the more restricted ConstBuf to refer to Buf. and declared in a class.
    What advantage would that provide when you already have a pointer member?
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler settings, references etc...
    By ejohns85 in forum C++ Programming
    Replies: 0
    Last Post: 05-14-2009, 04:53 AM
  2. VC++ 2005 Express: missing references page
    By psychopath in forum Tech Board
    Replies: 1
    Last Post: 08-21-2006, 04:55 PM
  3. Vector of references
    By roktsyntst in forum C++ Programming
    Replies: 5
    Last Post: 04-15-2003, 06:40 PM
  4. declare references to references works!
    By ManuelH in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2003, 08:14 AM
  5. Pointers and references...
    By SushiFugu in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 04:21 PM