C ++ unresolved external character

I have a class setting, and from this class I use inheritance.

In file ah

class a
{
public:
    virtual void print();
};

In the bh file:

#include "a.h"
#include <iostream>
class b: public a
{
public:
    void print();
};

And in b.cpp

#include "a.h"
#include "b.h"
void b::print(){};

In the main file, I include both of these files:

#include "a.h"
#include "b.h"

However, I get an unresolved character to print a virtual function. The a.obj file is listed as the file generating the error. What am I doing wrong? If I translate b.cpp to bh below the class definition, it works fine.

+5
source share
3 answers

You have an implementation for b :: print, but not for :: print. What happens if an instance of an object of class a is called print () on it? i.e.

a o;
o.print();

b :: print overrides a :: print, but you still need to have a :: print implementation (unless you make it pure virtual).

a, :

virtual void print() = 0;

, . , , .

+9

, b.cpp print() Add, b.

+1

I think you need to push at the end of the class interface

0
source

All Articles