How the instance of a class can pass itself by a function?
<p>How can I pass the "current class" throw a function(constructor) of another class by reference?</p>

<p>In this example I want to pass the "current" class A to the class C (with C and B polymorphic), the class C must be able to use the function A::getValue() and return the correct value.</p>

<p>Can I do it using using <strong>this</strong> ( bc = new C(??this??); )?</p>

<p>Is the constructor C(A aTemp) correct ? The goal is to pass the class via reference...</p>

<p>main.cc</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;
#include "A.h"
#include "B.h"
#include "C.h"
int main()
{
  A * cA = new A();
  std::cout &lt;&lt; "main: "&lt;&lt;  std::endl;
  cA-&gt;aRun();
  return 0;
}
</code></pre>

<p>A.h</p>

<pre><code>#ifndef A_h
#define A_h
#include "B.h"
#include "C.h"
class A{
public:
int iMain = 2;
void aRun(){B *bc; bc = new C(??this??);}
void setValue(int temp){iMain = temp;};
int getValue(){return iMain;};
};
#endif
</code></pre>

<p>B.h</p>

<pre><code>#ifndef B_h
#define B_h
#include "A.h"
class B{
 public:
 B(){};
 ~B(){};
};
#endif
</code></pre>

<p>C.cpp</p>

<pre><code>#include "C.h"
void C::cRun(){
    std::cout &lt;&lt; "cRun: " &lt;&lt; A-&gt;getValue() &lt;&lt; std::endl;
    }
</code></pre>

<p>C.h</p>

<pre><code>#ifndef C_h
#define C_h
#include &lt;iostream&gt;
#include &lt;string&gt;
#include "C.h"
#include "A.h"
class C:  public B{
 public:
 A *a;
 C(??A aTemp??){ a = aTemp};
 void cRun();
};
#endif
</code></pre>