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 6193599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:08:49+00:00 2026-05-24T03:08:49+00:00

I have a newbie question about how to assign class member (setter). I am

  • 0

I have a newbie question about how to assign class member (setter). I am used to scripting and mostly there it’s done via (in python)

def set_mymember(mymember):
     self.mymeber = mymember

My coworker told me “self” and “this” are not needed in C++ , “this” exists and it’s not wrong in this context but that would be hard to understand for me so he said I should not care. So I first tried according to his advice:

My class definition: – (it should create a sql query string)

class Query
{

public:
   Query() { }
   ~Query() { }

   void setoptions( std::string qtext_where="", bool qtext_erl=true, std::vector<std::string> kids=std::vector<std::string>() );
   Query build_query( );

   void set_db_table( std::string db_table );
   void set_db_key( std::string db_key );
   void set_m_qtext( std::string m_qtext );
   void set_foo( std::string foo );

   std::string sql();
   std::string get_sql_update();

private:
   std::string m_db_table;       // Tabellenname
   std::string m_db_key;         // Tabellen-key

   std::string m_qtext_where;    // add.optionale where clause
   std::string m_qtext;          // fertiger SELECT
   std::string m_sql_update;     // fertiger UPDATE
   bool m_erl;                   // nur erledigte waehlen?
   std::vector<std::string> m_kids;    // Liste von keys zu selecten
};

ANd here’s one of the setter methods: I call them with filled string and vector, double check it in this code

void Query::setoptions( string qtext_where, bool erl, vector<string> kids ) {
   m_qtext_where  = qtext_where;
   m_erl          = erl;
   m_kids = kids;     
}

But when my app later calls query.build_query()

the variables are empty

Query Query::build_query( ) {
   cout << "kids size" << m_kids.size() << endl;
   cout << "m_qtext_where " << m_qtext_where << endl;
   // Query zur auswahl der zu uebertragenden Datensaetze
   string sql_update = "UPDATE " + m_db_table;

   string qtext = "SELECT * FROM " + m_db_table;
   string qtext_order = " ORDER BY " + m_db_key;
   (...)

EDIT: So here’s part of the app code which calls 1.setoptions, and 2.build_query

       // read file line by line into vector of strings
       vector<string> text_file;
        ifstream ifs( input );
        string temp;
        while( getline( ifs, temp ) ) {
           if (temp.substr(0,1) == "#" ) {
              cout << "COMMENT: " << temp << endl;
              continue;
           }
           cout << temp << endl;
           text_file.push_back( temp );
        }
        // check: yes, vector has a size = number of lines
        cout << "text_file size " << text_file.size() << endl;

        // create Query object
        Query query = Query();
        // set the members, bool erl = true
        query.setoptions( "", erl, text_file );
        // call 2nd method         
        q2 = query.build_query();
  • 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-24T03:08:50+00:00Added an answer on May 24, 2026 at 3:08 am

    Can’t really tell whats going on without the full code, but I suspect that you’re returning a query object from query.build_query that isn’t a full copy of the query object, if that makes sense? Can you include the full text of build_query?

    Also, I’d make the build_query method void, and not try to assign a fresh Query object back to a second Query object (q2) at all (unless you really need to, again, can’t really tell without the full code), something like this:

    void Query::build_query( ) {
        std::cout << "kids size" << m_kids.size() << std::endl;
        std::cout << "m_qtext_where " << m_qtext_where << std::endl;
    }
    
    main
    {
        ...
        Query query = Query();
        // set the members, bool erl = true
        query.setoptions( "", true, text_file );
        // call 2nd method         
        query.build_query();
    }
    

    Also, just being pedantic here, but given that you’re providing default args for all the options, I’d be inclined to initialise them in the constructor like this:

    Query::Query() 
        : m_qtext_where("")
        , qtext_erl(true)
        , kids (std::vector<std::string>()
    {}
    

    And then instead of a setOptions method, have setters for each individual variable:

    void setWhere(std::string qtext_where) {m_qtext_where = qtext_where ;}
    void setErl(bool query_erl) { m_erl = query_erl; }
    void setKids(std::vector<std::string> kids) { m_kids = kids; }
    

    which you call only when you need to..

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

Sidebar

Related Questions

I have a newbie question about integrating two iOS apps. I have created an
I'm a Ruby newbie. Have a very basic question about static and instance variables.
Swing newbie question... I have a system where there is a large number of
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Newbie question. I have two c# classes - a code class (say, CodeClass) and
I have a newbie question about the following: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
Sorry about this newbie question. Is there a way to execute multiple sentences at
i'm a pl/sql newbie. now i have a question about oracle type . i
Following up on my previous newbie question about Paypal , I have a new
I am a Git newbie and have a question about how I should set

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.