gpt4 book ai didi

c++ - 架构 x86_64 的 undefined symbol

转载 作者:太空宇宙 更新时间:2023-11-04 15:26:34 25 4
gpt4 key购买 nike

<分区>

好的,我正在学习 C++,但我遇到了这个错误

Undefined symbols for architecture x86_64:
"Point::set(int, int)", referenced from:
Point::Point(int, int)in ccHkya9E.o
"Point::add(Point const&)", referenced from:
Point::operator+(Point const&)in ccHkya9E.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

这是我的代码

#include<iostream>

using namespace std;

class Point {
private:
int x, y;
public:
Point() {}
Point(int new_x, int new_y) {set(new_x, new_y);}
Point (const Point & src) {set(src.x, src.y);}

//Operations
Point add (const Point &pt);
Point sub (const Point &pt);
Point operator+(const Point &pt) {return add(pt);}
Point operator-(const Point &pt) {return sub(pt);}
//other member functions
void set(int new_x, int new_y);
int get_x() const {return x;}
int get_y() const {return y;}
};

int main() {
Point point1(20,20);
Point point2(0,5);
Point point3(-10, 25);
Point point4=point1+point2+point3;

cout<<"the point is"<<point4.get_x();
cout<<","<<point4.get_y()<<"."<<endl;
return 0;
}

感谢任何帮助!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com