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

  • Home
  • SEARCH
  • 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 6774675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:48:57+00:00 2026-05-26T15:48:57+00:00

I have a class State that has a string data type called moveType .

  • 0

I have a class State that has a string data type called moveType. In the implementation of my code, I am calling a setter void setMoveType(string _moveType); and it’s implemented with just moveType = _moveType;

When I call my getter string getMoveType() const; on an instance of State and output it to cout, nothing is displayed.

I am couting upon entering the getMoveType() function. The parameter indeed has the correct value, but it appears that it’s not getting set at all.

Does anyone have any idea? I feel this is something simple/trivial in c++ that I’m just completely forgetting.

string  State::getMoveType() const {
    return moveType;
}

void State::setMoveType(string move_type)  {
    cout << "In setMoveType and param = " << move_type << endl;
    moveType = move_type;
}

std::cout << vec_possibleSuccessors[i].getMoveType() << endl; // within loop;

vector<State> vec_possibleSuccessors;

    if (_minState.canMoveUp()) {
        up = _minState.moveUp();
        up.setMoveType("UP");
        up.setF(f(up));
        vec_possibleSuccessors.push_back(up);
    }

In the above code, _minState and up are instances of State. Also, I have made sure that my copy constructor and assignment operator have been modified to include moveType assignments.

  • 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-26T15:48:58+00:00Added an answer on May 26, 2026 at 3:48 pm

    Well not an answer but a short example that works the way you seem to intend this to work:

    #include <string>
    
    class State
    {
      private:
        std::string m_moveType;
    
      public:
        State() : m_moveType( "unknown" ) {}
    
       std::string getMoveType() const { return m_moveType; }
       void setMoveType( const std::string& moveType ) { m_moveType = moveType; }
    };
    

    In your main function or were else you need a vector of States you could write this:

    #include <iostream>
    #include <vector>
    #include "State.h"
    
    int main()
    {
      std::vector< State > states;
      for( int i=0; i<10; ++i )
      {
        State newState;
        newState.setMoveType( "state" );
        states.push_back( newState );
      }
    
      // do whatever you need to do....
      std::vector< State >::iterator it;
      std::vector< State >::iterator end = states.end();
      for( it=states.begin(); it != end; ++it )
        std::cout << (*it).getMoveType() << std::endl;
    
      return 0;
    }
    

    A few remarks:

    • passing parameters by value like setMoveType( string s ) is not
      adviseable, pass const references instead. Passing by value incurrs a
      full copy of the passed object
    • be careful with includes and namespaces, in doubt take the extra time
      to type std::… if you intend to use a feature defined in namespace
      std, and never type using namespace std in a header file.
    • initialize private members to a sensible default and do it in the class
      initializer list
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that has a method: -(NSInteger) getCityCountForState:(NSString *)state CityArray:(NSMutableArray *)cityArray {
I have a series of data that is produced by state and information type.
I have a GUI tool that manages state sequences. One component is a class
I have a workflow that has a public State property that returns a custom
I have a Wifi class that has a couple of broadcast receivers that listen
I have a status field on a class that has an ID and a
OK, so I have a database field of type char(1) that has a small
I have a class that takes a string in this format: 000067000000000012620060324b38e2cab3353 , encrypts
I have the following mapping: <hibernate-mapping package=server.modules.stats.data> <class name=User table=user> <id name=id> <generator class=native></generator>
I have class method that returns a list of employees that I can iterate

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.