Note that there are some explanatory texts on larger screens.

plurals
  1. POcan not change an object's property within another object in C++
    primarykey
    data
    text
    <p>I have the following code written in C++:</p> <pre><code>#include&lt;iostream&gt; #include&lt;vector&gt; using namespace std; class cViews { string viewName; double minD; vector&lt;double&gt; dss; public: string minInput1, minInput2; cViews(string); cViews(); void setName(string s) { viewName = s; } string getName() { return viewName; } void setMinI(string m) { minInput1 = m; } string getMinI() { return minInput1; } void setMinD(double d) { minD = d; } double getMinD() { return minD; } void addD(vector&lt;double&gt; k){ dss = k; } vector&lt;double&gt; getD(){ return dss; } }; cViews::cViews(string str) { viewName = str; vector&lt;double&gt; dss = vector&lt;double&gt;(); } cViews::cViews() { vector&lt;double&gt; dss = vector&lt;double&gt;(); } class Obj{ string name; cViews dist; public: Obj(string); void setName(string s) { name = s; } string getName() { return name; } void addDist(cViews k){ dist = k; } cViews getDist(){ return dist; } }; Obj::Obj(string str) { name = str; cViews dist(); } void changeViewN(cViews *v, string s){ v-&gt;setMinI(s); } int main(){ Obj o1("Object1"); cViews v3; cViews v1("View 1"); v1.setMinI("View 2"); v1.setMinD(1); o1.addDist(v1); cout &lt;&lt; o1.getName() &lt;&lt; " " &lt;&lt; o1.getDist().getMinI() &lt;&lt; endl; v3 = o1.getDist(); changeViewN(&amp;v3, "Changed"); cout &lt;&lt; o1.getName() &lt;&lt; " " &lt;&lt; o1.getDist().getMinI() &lt;&lt; endl; return 0; } </code></pre> <p>Output is:</p> <pre><code>Object1 View 2 Object1 View 2 </code></pre> <p>The problem here is I am trying to change the value of an object that was created within another object.</p> <p>Output should be:</p> <pre><code>Object1 View 2 Object1 Changed </code></pre> <p>Any help is greatly appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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