I am new to C++ in terms of large projects distributed over various source files.

When I compile(gcc compiler) I get the following error: undefined reference to 'C::C()'

I have this code:

/src/lib/abstract/A.cpp

#include "src/plugins/geo/C.h"
#include "B.h"

class A:public B
{
 public; 
  A()
   {
     B m_b;
   }
  void speed()
  {
    m_b = new C();
    m_b->cspeed();
  }
}

/src/lib/B.h

class B
{
public:
virtual int cspeed();
}

in /src/pligins/geo/C.h

#include "B.h"
class C:public B
{ private:
   int speed=5;
  public: 
  C()
  {}
  int cspeed()
  {
    return speed;
  }
}

First, I'm not sure if you actually copied and pasted, but in your A class, public; should be public: .

Second, you need semicolons after the closing brace of all of the class definitions.

The main problem is that you are defining m_b in the constructor of A (a local variable), then trying to access it from a member function of A. You need to define m_b as a member variable of A (outside of any functions, including the constructor).

Good luck,
Dave

thanks..your advise helped me to figure it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.