gpt4 book ai didi

C++:Xcode 错误; "Graph::Coordinate::Coordinate()",引用自:

转载 作者:行者123 更新时间:2023-11-28 08:24:21 26 4
gpt4 key购买 nike

在我正在编写的程序中,我为两个类(坐标和图形)编写了代码,其中一个将另一个作为构造函数参数。当我尝试编译它时,出现以下 Graph.cpp 错误:

undefined symbol : “Graph::Coordinate::Coordinate(double)”,引用自: Graph.o 中的 Graph::Graph() Graph.o 中的 Graph::Graph() “Graph::Coordinate::Coordinate()”,引用自: Graph::Graph(Graph::Coordinate, Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate, Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate)in Graph.o Graph::Graph(Graph::Coordinate)in Graph.o Graph.o 中的 Graph::Graph() Graph.o 中的 Graph::Graph() Graph.o 中的 Graph::Graph() Graph.o 中的 Graph::Graph() Graph.o 中的 Graph::Graph() Graph.o 中的 Graph::Graph()ld:未找到符号collect2: ld 返回了 1 个退出状态

我检查了代码,没有发现任何异常。下面是四个类文件:(抱歉,要筛选的代码太多了。)

坐标.h

class Graph{
#include "Coordinate.h"
public:
Graph();
Graph(Coordinate);
Graph(Coordinate, Coordinate);
Graph(Coordinate, Coordinate, Coordinate);

void setXSize(int);
void setYSize(int);

void setX(int); //int corresponds to coordinates 1, 2, or 3
void setY(int);
void setZ(int);

int getXSize();
int getYSize();

double getX(int); //int corresponds to coordinates 1, 2, or 3
double getY(int);
double getZ(int);

void outputGraph();
void animateGraph();


private:
int xSize;
int ySize;

Coordinate coord1;
Coordinate coord2;
Coordinate coord3;

};

坐标.cpp

#include <iostream>
#include "Coordinate.h"


Coordinate::Coordinate()
{
xCoord = 1;
yCoord = 1;
zCoord = 1;

xVel = 1;
yVel = 1;
zVel = 1;
}
Coordinate::Coordinate(double xCoo)
{
xCoord = xCoo;
yCoord = 1;
zCoord = 1;

xVel = 1;
yVel = 1;
zVel = 1;
}
Coordinate::Coordinate(double xCoo,double yCoo)
{
xCoord = xCoo;
yCoord = yCoo;
zCoord = 1;

xVel = 1;
yVel = 1;
zVel = 1;
}
Coordinate::Coordinate(double xCoo,double yCoo,double zCoo)
{
xCoord = xCoo;
yCoord = yCoo;
zCoord = zCoo;

xVel = 1;
yVel = 1;
zVel = 1;
}

void Coordinate::setXCoord(double xCoo)
{
xCoord = xCoo;
}
void Coordinate::setYCoord(double yCoo)
{
yCoord = yCoo;
}
void Coordinate::setZCoord(double zCoo)
{
zCoord = zCoo;
}
void Coordinate::setXVel(double xVelo)
{
xVel = xVelo;
}
void Coordinate::setYVel(double yVelo)
{
yVel = yVelo;
}
void Coordinate::setZVel(double zVelo)
{
zVel = zVelo;
}


double Coordinate::getXCoord()
{
return xCoord;
}
double Coordinate::getYCoord()
{
return yCoord;
}
double Coordinate::getZCoord()
{
return zCoord;
}
double Coordinate::getXVel()
{
return xVel;
}
double Coordinate::GetYVel()
{
return yVel;
}
double Coordinate::GetZVel()
{
return zVel;
}

Graph.h

class Graph{
#include "Coordinate.h"
public:
Graph();
Graph(Coordinate);
Graph(Coordinate, Coordinate);
Graph(Coordinate, Coordinate, Coordinate);

void setXSize(int);
void setYSize(int);

void setX(int); //int corresponds to coordinates 1, 2, or 3
void setY(int);
void setZ(int);

int getXSize();
int getYSize();

double getX(int); //int corresponds to coordinates 1, 2, or 3
double getY(int);
double getZ(int);

void outputGraph();
void animateGraph();


private:
int xSize;
int ySize;

Coordinate coord1;
Coordinate coord2;
Coordinate coord3;

};

图形.cpp

#include "Graph.h"
#include "Coordinate.h"
#include <iostream>
#include <ctime>

using namespace std;

Graph::Graph()
{
Coordinate coord1(0);
}
Graph::Graph(Coordinate cOne)
{
coord1 = cOne;

xSize = 20;
ySize = 20;
}
Graph::Graph(Coordinate cOne, Coordinate cTwo)
{
coord1 = cOne;
coord2 = cTwo;

xSize = 20;
ySize = 20;
}
Graph::Graph(Coordinate cOne, Coordinate cTwo, Coordinate cThree)
{
coord1 = cOne;
coord2 = cTwo;
coord3 = cThree;

xSize = 20;
ySize = 20;
}

void Graph::setXSize(int size)
{
xSize = size;
}
void Graph::setYSize(int size)
{
ySize = size;
}

int Graph::getXSize()
{
return xSize;
}
int Graph::getYSize()
{
return ySize;
}

void Graph::outputGraph()
{

}
void Graph::animateGraph()
{

}

非常感谢您的帮助!

最佳答案

你把#include 放在你的类中。这导致内部类 Graph::Coordinate 定义链接器找不到。将 #include 移到 Graph 类之前。

关于C++:Xcode 错误; "Graph::Coordinate::Coordinate()",引用自:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4573217/

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