C++ Can virtual methods be implemented when declaring an object?
<p>I'm back to working with C++ after quite a long while using Java almost exclusively, so I'm hitting snags when trying to do things I could do in Java but can't in C++.</p>

<p>In this case, in Java I could do something like this:</p>

<pre><code>class MyClass
{
   public void myMethod();
}

// -------

MyClass myObject = new MyClass(){
    myMethod()
    {
      // Do stuff
    }
};
</code></pre>

<p>In essence, I'm implementing the logic for <em>myMethod()</em> when declaring the <em>MyClass</em> object (Note that my syntax might be off).</p>

<p>I'm trying to find out if there's an equivalent for C++</p>

<p>My specific use case is a set of tests for a Server/Client architecture where the Test objects extend the base Server/Client abstract classes and implement the virtual methods controlling their behaviour. 
I need to modify this behaviour for each specific test, and it would come in handy to be able to "inline" these implementations when declaring the Test objects, rather than having to implement several variations on the Test object for each specific test.</p>

<p>Thanks!</p>

<p><strong>EDIT:</strong> I've implemented <em>Smeeheey</em>'s answer as follows, and works like a charm</p>

<pre><code>int main(...)
{

   class TestServer : public BaseServer
   {
      public:
         TestServer(...) : BaseServer(...){...} //Constructor

         void virtualFunction(...){...} // Extended function
   };

   TestServer testInstance(...);

   // Execute tests using testInstance object
</code></pre>

<p>}</p>