-1
我試圖編譯我的項目,但是編譯器正顯示出每一個有到卡FigureCard類呼叫時出現以下錯誤:未定義refrence類卡
bin/FigureCard.o: In function `FigureCard::FigureCard()':
/users/studs/bsc/2016/dalitroz/workspace/ass1/src/FigureCard.cpp:5: undefined reference to `Card::Card()'
bin/FigureCard.o: In function `FigureCard::FigureCard(Figure, Shape)':
/users/studs/bsc/2016/dalitroz/workspace/ass1/src/FigureCard.cpp:6: undefined reference to `Card::Card(Shape)'
bin/FigureCard.o: In function `FigureCard::~FigureCard()':
/users/studs/bsc/2016/dalitroz/workspace/ass1/src/FigureCard.cpp:10: undefined reference to `Card::~Card()'
bin/FigureCard.o: In function `FigureCard::toString[abi:cxx11]()':
/users/studs/bsc/2016/dalitroz/workspace/ass1/src/FigureCard.cpp:26: undefined reference to `Card::getCapitalShape[abi:cxx11]()'
/users/studs/bsc/2016/dalitroz/workspace/ass1/src/FigureCard.cpp:28: undefined reference to `Card::getCapitalShape[abi:cxx11]()'
/users/studs/bsc/2016/dalitroz/workspace/ass1/src/FigureCard.cpp:30: undefined reference to `Card::getCapitalShape[abi:cxx11]()'
/users/studs/bsc/2016/dalitroz/workspace/ass1/src/FigureCard.cpp:31: undefined reference to `Card::getCapitalShape[abi:cxx11]()'
bin/FigureCard.o:(.rodata._ZTV10FigureCard[_ZTV10FigureCard]+0x28): undefined reference to `Card::getShape()'
bin/FigureCard.o:(.rodata._ZTI10FigureCard[_ZTI10FigureCard]+0x10): undefined reference to `typeinfo for Card'
這是我的makefile:
CC = g++
CFLAGS = -g -Wall -Weffc++ -std=c++11
LFLAGS = -L/usr/lib
# All Targets
all: reviiyot
# Tool invocations
# Executable "reviiyot" depends on the files reviiyot.o and run.o.
reviiyot: bin/reviiyot.o bin/Card.o bin/Hand.o bin/Deck.o bin/Player.o bin/NumericCard.o bin/FigureCard.o
@echo 'Building target: reviiyot'
@echo 'Invoking: C++ Linker'
$(CC) -o bin/Card.o bin/Hand.o bin/Deck.o bin/Player.o bin/reviiyot.o bin/NumericCard.o bin/FigureCard.o $(LFLAGS)
@echo 'Finished building target: reviiyot'
@echo ' '
# Depends on the source and header files
bin/reviiyot.o: src/reviiyot.cpp
$(CC) $(CFLAGS) -c -Iinclude -o bin/reviiyot.o src/reviiyot.cpp
bin/Card.o: src/Card.cpp
$(CC) $(CFLAGS) -c -Iinclude -o bin/Card.o src/Card.cpp
bin/NumericCard.o: src/NumericCard.cpp
$(CC) $(CFLAGS) -c -Iinclude -o bin/NumericCard.o src/NumericCard.cpp
bin/FigureCard.o: src/FigureCard.cpp
$(CC) $(CFLAGS) -c -Iinclude -o bin/FigureCard.o src/FigureCard.cpp
bin/Hand.o: src/Hand.cpp
$(CC) $(CFLAGS) -c -Iinclude -o bin/Hand.o src/Hand.cpp
bin/Deck.o: src/Deck.cpp
$(CC) $(CFLAGS) -c -Iinclude -o bin/Deck.o src/Deck.cpp
bin/Player.o: src/Player.cpp
$(CC) $(CFLAGS) -c -Iinclude -o bin/Player.o src/Player.cpp
#Clean the build directory
clean:
rm -f bin/*
這是爲H文件(Card.h):
#ifndef CARD_H_
#define CARD_H_
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
enum Shape {
Club,
Diamond,
Heart,
Spade
};
enum Figure {
Jack,
Queen,
King,
Ace
};
class Card {
private:
Shape shape;
public:
Card();
Card(Shape myShape);
virtual string toString() = 0; //Returns the string representation of the card "<value><shape>" exp: "12S" or "QD"
virtual ~Card();
virtual Shape getShape();
virtual int getType(int n) const =0;
string getCapitalShape();
};
class FigureCard : public Card {
private:
Figure figure;
public:
FigureCard();
FigureCard(Figure myFigure, Shape myShape);
virtual ~FigureCard();
string toString() override;
Figure getFigure() const ;
int getType(int n)const override;
};
#endif
Class.cpp:
#include "../include/Card.h"
using namespace std;
Card::Card(): shape(Club){
}
Card::Card(Shape myShape) : shape(myShape){
}
//////check
Card:: ~Card(){}
Shape Card::getShape()
{
return shape;
}
//////check
string Card:: getCapitalShape(){
if(shape== Club)
return "C";
else if (shape == Diamond)
return "D";
else if (shape == Heart)
return "H";
else return "S";
}
string Card::toString() {
return getCapitalShape();
}
和FigureCard:
#include "../include/Card.h"
FigureCard::FigureCard(): Card(), figure(Jack){}
FigureCard::FigureCard(Figure myFigure, Shape myShape) : Card(myShape), figure(myFigure) {
}
FigureCard:: ~FigureCard()
{}
Figure FigureCard::getFigure() const
{
return figure;
}
int FigureCard::getType(int n) const
{
return figure+1+n;
}
string FigureCard ::toString() {
if(figure== Jack)
return "J"+Card::getCapitalShape();
else if (figure == Queen)
return "Q"+Card::getCapitalShape();
else if (figure == King)
return "K"+Card::getCapitalShape();
else return "A"+Card::getCapitalShape();
}
很想幫助,謝謝:)
感謝它工作:) – DRoz92