Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ private member variable unknown in another function
    primarykey
    data
    text
    <p>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)</p> <pre><code>def set_mymember(mymember): self.mymeber = mymember </code></pre> <p>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:</p> <p>My class definition: - (it should create a sql query string)</p> <pre><code>class Query { public: Query() { } ~Query() { } void setoptions( std::string qtext_where="", bool qtext_erl=true, std::vector&lt;std::string&gt; kids=std::vector&lt;std::string&gt;() ); 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&lt;std::string&gt; m_kids; // Liste von keys zu selecten }; </code></pre> <p>ANd here's one of the setter methods: I call them with filled string and vector, double check it in this code</p> <pre><code>void Query::setoptions( string qtext_where, bool erl, vector&lt;string&gt; kids ) { m_qtext_where = qtext_where; m_erl = erl; m_kids = kids; } </code></pre> <p>But when my app later calls <code>query.build_query()</code></p> <p>the variables are empty </p> <pre><code>Query Query::build_query( ) { cout &lt;&lt; "kids size" &lt;&lt; m_kids.size() &lt;&lt; endl; cout &lt;&lt; "m_qtext_where " &lt;&lt; m_qtext_where &lt;&lt; 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; (...) </code></pre> <p><strong>EDIT</strong>: So here's part of the app code which calls 1.setoptions, and 2.build_query</p> <pre><code> // read file line by line into vector of strings vector&lt;string&gt; text_file; ifstream ifs( input ); string temp; while( getline( ifs, temp ) ) { if (temp.substr(0,1) == "#" ) { cout &lt;&lt; "COMMENT: " &lt;&lt; temp &lt;&lt; endl; continue; } cout &lt;&lt; temp &lt;&lt; endl; text_file.push_back( temp ); } // check: yes, vector has a size = number of lines cout &lt;&lt; "text_file size " &lt;&lt; text_file.size() &lt;&lt; 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(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload