Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:17:24+00:00 2026-05-26T18:17:24+00:00

I am trying to reference to a class variable which is a vector and

  • 0

I am trying to reference to a class variable which is a vector and change value of the vector. I got this error. what am I doing wrong? thanks in advance. ( “pick” is just an int. )

 class tic
{
private:
vector<int> move;   //calculate moves
vector<int> value1; //player1's points
vector<int> value2; //player2's points
vector<int> value;  //exchange value
vector<string> board;   //numbers on the board
public:
void setboard ();   //output numbers on the board
void setvalue();    //each number's value corresponding to the numbers on the board
void setvalue12();  //values of player1 and playe2
void set(); //setboard, setvalue, setvalue12
void printboard (int &pick); //print board
int pick(int &m);       //pick a number on the board
bool sum15 (vector<int> &sum15);  //check if sum is 15 of any combination of 3
int WinLoseDraw (int &pick, int player);    //win=0, continue=1, draw=20
void WLD(int &player)
{   
    vector<int> &temp=(player==1)?this->value1:this->value2;
    temp[pick-1]=value[pick-1]; //input values
    if (sum15(temp))    //if any sum of 3 is 15
    {
        cout<<"WINS!"<<endl;
    }
}

};

this is the original codes. I am trying to simply this part with a member function or an inline function named WLD

    if (player==1)  
    {       
        value1[pick-1]=value[pick-1];   //input values

        if (sum15(this->value1))    //if any sum of 3 is 15
            {
                cout<<"PLAYER1 WINS!"<<endl;
                return 0;
            }
    }
    else  
    {
        value2[pick-1]=value[pick-1];

        if (sum15(this->value2))
        {
            cout<<"PLAYER2 WINS!"<<endl;
            return 0;
        }
    }

with the updated codes. I got erros on “temp[pick-1]=value[pick-1];

tic.h: In member function ‘void tic::WLD(int&)’:
tic.h:28: error: invalid use of member (did you forget the ‘&’ ?)
tic.h:28: error: invalid use of member (did you forget the ‘&’ ?)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:17:24+00:00Added an answer on May 26, 2026 at 6:17 pm

    A reference is not assignable, only constructible. You could try doing:

    vector<int>& temp = ( player == 1 ) ? this->value1 : this->value2;
    

    Update:

    With the updated code, all you have to do is drop the const in temp to make it work. Note that you have lvalues, the r in rvalues comes not from reference but from right, as in usable on the right side of an expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use an excpetion class which could provide location reference for XML parsing,
I'm getting a Can't use an undefined value as a HASH reference error trying
In the below code, i am trying to reference an external .dll, which creates
I've got a GWT 1.6 project in Eclipse 3.4 and am trying to reference
Trying the ggplot2 examples in the online reference manual, and particularly in this page
I am trying to add an error class to an input textbox to show
I was trying to lock a Boolean variable when I encountered the following error
I have an Objective-C view controller class, from which I am trying to call
I was trying to compile some C++ code in Xcode and I got this
I have a class Car which has a class scope variable cost, i understand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.