Thread: A Question/problem with classes and sending a variable to an object

  1. #16
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    257
    Code:
    void record::setp_number(int number)
    {
         number = p_number;
    }
    Have a REAL good look at what you're doing in this method.

  2. #17
    Trainee Geek Draylath's Avatar
    Join Date
    Nov 2011
    Location
    Cambridge
    Posts
    24
    From what I understand so far (which I grant you is not that much) that should be about right. I've put in variable "number" input from main and assigned p_number that value. Obviously this isn't totally right as it is not working. Do I have to do something like passing by reference or have I got something in the syntax wrong because now I am just lost.

    Thanks you all for your help on this though

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Compare the code for the setp_number function that you wrote in post #1 with the code you posted in post #15. In particular, what are you assigning to, and why?
    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

  4. #19
    Trainee Geek Draylath's Avatar
    Join Date
    Nov 2011
    Location
    Cambridge
    Posts
    24
    got it!

    I think I need to re read the parts of my book on the assignment operator and assigning values to variables. I thought that number = p_number and p_number = number would have been the same but then of course = does not mean equals == does.

    Thanks for your patience and help in getting this sorted and I love the way you guys just didn't tell me how to fix it straight out but get me to think.

    Once again thankyou antred, Jim and Laserlight

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sending a structure variable through MPI in C
    By shrek in forum C Programming
    Replies: 8
    Last Post: 07-01-2011, 09:57 AM
  2. Pointers- Difference From Sending a Copy of the Object?
    By Shokwav in forum C++ Programming
    Replies: 7
    Last Post: 05-31-2011, 01:28 PM
  3. Global variable vs parameter 'sending'.
    By MipZhaP in forum C++ Programming
    Replies: 16
    Last Post: 04-03-2011, 09:58 AM
  4. Replies: 12
    Last Post: 02-12-2009, 02:39 PM
  5. Creating an object in a dll & sending it to an exe file
    By SteveRodrigue in forum C++ Programming
    Replies: 6
    Last Post: 12-14-2006, 02:01 PM