'Invalid Use of Member'

This is a discussion on 'Invalid Use of Member' within the C++ Programming forums, part of the General Programming Boards category; Hi there, I am tryign to write a function and i need part of it to access and change the ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    1

    'Invalid Use of Member'

    Hi there, I am tryign to write a function and i need part of it to access and change the variables of an object (seems simple enough)

    I create the object using

    Code:
    canyon_section result(0,0);
    in the main() function of a .cpp file.

    Below is the constructor for the object:


    Code:
    class canyon_section
    {
    public:
    	canyon_section( int first_value, int second_value )
    	: first_value_( first_value ), 
    	  Second_value_( second_value ) 
    	{
    	}
    This object 'result' is then passed by reference to a function in a header file:

    Code:
    next_section_result = get_next_section(result);
    i then use the code:

    Code:
    result.first_value = random_int();
    result.second_value = random_int();
    to try and modify the 2 integer values of the object.

    Only problem is when I try to compile the main.cpp file I get a compile error:

    'invalid use of member (did you forget the `&' ?) '


    with a line reference to the 'result.first_value.....' line (same error for the second_value line as well).

    Am i missing something?

    Thanks,

    stu673

    *edited to include funciton call & constructor
    Last edited by stu673; 02-10-2005 at 11:25 AM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Why so cryptic? Post the funtion call as well as the function definition.

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    I agree. More code.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    An odd error, you wouldn't by chance have first_value and second_value declared as private or protected members, would you?

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    You have one mistake in your constructor. Still need to see the function definition that contains the lines:

    result.first_value = random_int();
    result.second_value = random_int();

  6. #6
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    According to your constructor, neither first_value nor second_value are members of your class. first_value_ and Second_value_ are. You may consider using more informative and case-uniform identifiers. For instance, I prefer to use "m_" before any member variables of a class.
    Code:
    class myClass
    {
    public:
       int m_a;
       //etc...
    };
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

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. New to C++ Classes
    By Cypher in forum C++ Programming
    Replies: 122
    Last Post: 07-05-2007, 02:49 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM

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