0

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;
  }
}

Edited by akssps011: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by akssps011
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.