Like Tree1Likes

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

This is a discussion on A Question/problem with classes and sending a variable to an object within the C++ Programming forums, part of the General Programming Boards category; Code: void record::setp_number(int number) { number = p_number; } Have a REAL good look at what you're doing in this ...

  1. #16
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    249
    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
    21,739
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    iMalc likes this.

Page 2 of 2 FirstFirst 12
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, 01: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, 01:01 PM

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