Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved External Symbol linker error (C++)

Tags:

c++

linker

I am trying to develop abstract design pattern code for one of my project as below.. But, I am not able to compile the code ..giving some compile errors(like "unresolved external symbol "public: virtual void __thiscall Xsecs::draw_lines(double,double)" (?draw_lines@Xsecs@@UAEXNN@Z)" ).. Can any one please help me out in this...

#include "stdafx.h"
#include <iostream>
#include <vector>
#include "Xsecs.h"
using namespace std;
//Product class

class Xsecs
{
public:
    virtual void draw_lines(double pt1, double pt2);
    virtual void draw_curves(double pt1, double rad);
};

class polyline: public Xsecs
{
public:
    virtual void draw_lines(double pt1,double pt2)
    {
        cout<<"draw_line in polygon"<<endl;
    }
     virtual void draw_curves(double pt1, double rad)
    {
        cout<<"Draw_curve in circle"<<endl;
    }
    /*void create_polygons()
    {
        cout<<"create_polygon_thru_draw_lines"<<endl;
    }*/
};

class circle: public Xsecs
{
 public:
     virtual void draw_lines(double pt1,double pt2)
    {
        cout<<"draw_line in polygon"<<endl;
    }
     virtual void draw_curves(double pt1, double rad)
    {
        cout<<"Draw_curve in circle"<<endl;
    }
    /*void create_circles()
    {
        cout<<"Create circle"<<endl;
    }*/
};

//Factory class
class Factory
{
public:
 virtual polyline* create_polyline()=0;
 virtual circle* create_circle()=0;
};

class Factory1: public Factory
{
public:
      polyline* create_polyline()
{
    return new polyline();
}
      circle* create_circle()
{
    return new circle();
}
};

class Factory2: public Factory
{
public:
      circle* create_circle()
{
    return new circle();
}
     polyline* create_polyline()
{
    return new polyline();
}
};

int _tmain(int argc, _TCHAR* argv[])
{
    Factory1 f1;
    Factory * fp=&f1;
    return 0;
}
like image 500
Red Avatar asked Jan 22 '23 04:01

Red


1 Answers

I presume you were attempting to create a virtual base class. You need to add '= 0' to the end of the draw_lines and draw_curves methods in the class Xsecs

class Xsecs
{
public:
    virtual void draw_lines(double pt1, double pt2) = 0;
    virtual void draw_curves(double pt1, double rad) = 0;
};

the compiler is complaining as you haven't any implementation for the methods in question.

like image 178
Petesh Avatar answered Jan 31 '23 03:01

Petesh