C++: Error in Xcode; "Graph::Coordinate::Coordinate()", referenced from: ...
- by Alexandstein
In a program I am writing, I wrote for two classes (Coordinate, and Graph), with one of them taking the other as constructor arguments.
When I try to compile it I get the following error for Graph.cpp:
Undefined symbols:
"Graph::Coordinate::Coordinate(double)", referenced from:
Graph::Graph() in Graph.o
Graph::Graph() in Graph.o
"Graph::Coordinate::Coordinate()", referenced from:
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::Graph() in Graph.o
Graph::Graph() in Graph.o
Graph::Graph() in Graph.o
Graph::Graph() in Graph.o
Graph::Graph() in Graph.o
Graph::Graph() in Graph.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I checked the code and couldn't find anything out of the ordinary.
Here are the four class files: (Sorry if it's a lot of code to sift through.)
Coordinate.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;
};
Coordinate.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;
};
Graph.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()
{
}
Thanks very much for any help!