架构x86_64的未定义符号(复制构造函数) [英] Undefined symbols for architecture x86_64(copy constructor)

查看:241
本文介绍了架构x86_64的未定义符号(复制构造函数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试修复返回空向量的函数。我做了一些google搜索,它显示我需要一个复制构造函数的类,我不断收到这个错误:

I have try to fix the function returning empty vector. I have did some google search, it shows i need a copy constructor for the class Point, and i keep receiving this error:

Undefined symbols for architecture x86_64:   "Point::Point(Point const&)", referenced from:
      Core::render() in Week3_T.o
      Core::sortTriVertices(Point&, Point&, Point&) in Week3_T.o
      Core::decompose(std::__1::vector<Point, std::__1::allocator<Point> >) in Week3_T.o
      Core::drawTriangle(Point, Point, Point) in Week3_T.o
      Core::clipedge(std::__1::vector<Point, std::__1::allocator<Point> >, int, int, int, int) in Week3_T.o
      std::__1::enable_if<__is_forward_iterator<Point*>::value, void>::type std::__1::vector<Point, std::__1::allocator<Point>
>::__construct_at_end<Point*>(Point*, Point*) in Week3_T.o
      void std::__1::vector<Point, std::__1::allocator<Point> >::__push_back_slow_path<Point const>(Point const&) in Week3_T.o
      ... ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

和我的类:

class Point
{
public:
    int x;
    int y;
    Uint8 r;
    Uint8 g;
    Uint8 b;
    Point(int x, int y, Uint8 r, Uint8 g, Uint8 b) : x(x), y(y), r(r), g(g), b(b) {}
    Point& operator=(Point const &np){
        x=np.x;
        y=np.y;
        r=np.r;
        g=np.g;
        b=np.b;
        return *this;
    }
    Point(const Point& );
    Point(){}


};

和代码段:

std::vector<Point> Core::clipedge(vector<Point> polygon, int x0, int y0, int x1, int y1)
{

    int r=rand()%255;
    int g=rand()%255;
    int b=rand()%255;
    // For each side of the polygon, check the 4 cases of sutherland-hodgman.
    // Creating a temporary buffer to hold your new set of vertices for the clipped polygon.
    std::vector<Point> temp;
    temp.push_back(Point(1,2,255,255,255));
    int size = (int)polygon.size();

    for (int i = 0; i < size; ++i) {
       {....}
       //push_back clipped point
       temp.push_back(p1);
       {....}
    }
    return temp;

系统是OSX10.9.2,ide是xcode5.1.1编译器是apple llvm5.1

system is OSX10.9.2 and ide is xcode5.1.1 compiler is apple llvm5.1

我需要做什么来解决这个问题?

What i need to do to fix this? thanks for help.

推荐答案

正如其他答案中所指出的,您没有提供 Point :: Point(const Point&),但是你已经在 Point 类定义中声明它。但是你的类不需要对拷贝和赋值进行特殊的处理,所以解决你的问题是提供缺少的定义,而是删除拷贝构造函数的声明。也删除赋值运算符:

As has been pointed out in other answers, you have not provided the definition of Point::Point(const Point&), but you have declared it in your Point class definition. But your class requires no special handling of copy and assignment, so the solution to your problem is not to provide the missing definitions, but to remove the declaration of the copy constructor. Remove the assignment operator too:

class Point
{
public:
    int x;
    int y;
    Uint8 r;
    Uint8 g;
    Uint8 b;
    Point(int x, int y, Uint8 r, Uint8 g, Uint8 b) 
    : x(x), y(y), r(r), g(g), b(b) {}
};

编译器合成的版本会做正确的事。

The compiler-synthesized versions will do the right thing.

这篇关于架构x86_64的未定义符号(复制构造函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆