I'm creating a cpp program using functions that are applied to C++11. Even though the code seems correct and has no syntax errors i'm getting this message when i compile:
/tmp/cce9dpew.o: In function `Object::Object()':
classes.cpp:(.text+0xd): undefined reference to `vtable for Object'
/tmp/cce9dpew.o: In function `Object::~Object()':
classes.cpp:(.text+0x45): undefined reference to `vtable for Object'
/tmp/cce9dpew.o:(.rodata._ZTI6String[_ZTI6String]+0x10): undefined reference to `typeinfo for Object'
collect2: error: ld returned 1 exit status
I have to add here that if i put all those .cpp and .h files in one it runs Aok printing constructor and destructor cout's just fine. Can someone help?The code is below. compile recipe i used to run them all together: g++ -std=c++0x classes.h classes.cpp mainiz.cpp
classes.h:
#ifndef CLASSES_H
#define CLASSES_H
#include <iostream>
#include <cstring>
using namespace std;
class Object
{
    private:
        int id;
    public:
        Object();
        ~Object();
        void set_id(int ids);
        int get_id();
        void Equal(Object* bj) const;
        void Identical(Object* bj) const;
        virtual Object* clone();
        virtual void toString();        
};
class String:public Object
{
        string characters;
    public:
        String();
        ~String();
        void set_char(string a);
        string get_char();
        String* clone();
        void toString();    
        int Length();
        void Clear(string a);
        string& Concat(string &a);
        char At(char b);
        string& UpdateAt(string a,string charact);
        void Print(const string a) const;   
};
#endif //CLASSES_H
classes.cpp:
#include <iostream>
#include <cstring>
#include "classes.h"
using namespace std;
//FOR OBJECT CLASS
Object::Object(){ cout << "An object just got created." << endl;}
Object::~Object(){ cout << "An object just got destroyed." << endl; }
void Object::set_id(int ids) { this->id = ids; }
int Object::get_id() { return this->id;}
void Object::Equal(Object* bj) const
{
    if((this->id == bj->id))
    {
        cout << "The objects are equal." << endl;
    }
    else
    {
        cout << "The objects are not equal." <<endl;
    }
}
void Object::Identical(Object* bj) const
{
    if(this==bj)
    {
        cout << "The objects are identical." <<endl;
    }
    else
    {
        cout << "The objects are not identical." <<endl;
    }
}
//FOR STRING CLASS
String::String(){ cout << "String just created" << endl;}
String::~String(){ cout << "String to be destroyed" << endl;}
void String::set_char(string a) { this->characters = a;}
string String::get_char() { return this->characters;}
String* String::clone() { return this;}
void String::toString() {cout << "characters" << endl;}
int String::Length()
{ 
    string a = this->characters;
    return a.length();  
}
void String::Clear(string a)
{
    this->characters.clear();
}
string& String::Concat(string &a){  return (this->characters.append(a));}
char String::At(char b) { return (this->characters.find(b)); }
string& String::UpdateAt(string a,string charact)
{
    int position=this->characters.find(charact);
    return this->characters.replace(position,1,a);  
}
void String::Print(const string a) const { cout << "print of string:" << a << endl; }
mainiz.cpp:
#include <iostream>
#include <cstring>
#include "classes.h"
using namespace std;
int main()
{
    Object k;
    Object *st = new String;
    String d;
}
 
     
     
    