Thread: Syntax for implementing a function that returns a pointer

  1. #1
    Registered User
    Join Date
    Oct 2010
    Location
    San Francisco, CA
    Posts
    5

    Syntax for implementing a function that returns a pointer

    I have a List class with a function that returns a pointer value and it is declared as follows in a header file:

    Code:
    Node *Find(int key);
    I want to implement this function but I have no idea how to do it properly when the return type is a pointer. A thought it might be something a long the lines of:

    Code:
    // in the .cc file
    
    
    List::Node *::List::Find(int key)
    {
    
    // My implementation code
    
    
    return nodePtr;
    
    }
    However, this doesn't work and my searches for something similar have come up blank thus far. Thank you so much for your help!

    Best regards.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This:
    Code:
    List::Node *::List::Find(int key)
    should be:
    Code:
    List::Node* List::Find(int key)
    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
    Registered User
    Join Date
    Oct 2010
    Location
    San Francisco, CA
    Posts
    5
    Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 02:36 AM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM