為什么運行代碼出現這個,如何解決
error LNK2019: 無法解析的外部符號 "public: __thiscall Teacher::Teacher(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (??0Teacher@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z),該符號在函數 _main 中被引用
1>E:\C++練習\ConsoleApplication1\Debug\demo-2-xigou.exe : fatal error LNK1120: 1 個無法解析的外部命令
2015-09-15
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include "Coordinate.h"
#include "Line.h"
using namespace std;
/********************************************/
/*對象成員
要求:
? ? ?定義兩個類;
坐標類:Coordinate
數據成員:橫坐標m_iX,縱坐標m_iY
成員函數:構造函數,析構函數,數據成員的封裝函數
線段類:Line
數據成員:點A:m_coorA,點B:m_coorB
成員函數:構造函數,析構函數,數據成員封裝函數,信息打印函數
*/
/********************************************/
int main(void)
{
Line *p = new Line(1,2,3,4);
p->printInfo();
delete p;
p = NULL;
system("pause");
? ? return 0;
}
//代碼:Line.h
#include <iostream>
#include <stdlib.h>
#include "Coordinate.h"
using namespace std;
class Line
{
public:
Line(int x1,int y1,int x2,int y2);
~Line();
void setA(int x,int y);
void setB(int x,int y);
void printInfo();
private:
Coordinate m_coorA;
Coordinate m_coorB;
};
//Line.cpp
#include <iostream>
#include <stdlib.h>
#include "Coordinate.h"
#include "Line.h"
Line::Line(int x1,int y1,int x2,int y2):m_cooA(x1,y1),m_coorB(x2,y2)
{
cout << "Line()" << endl;
}
Line::~Line()
{
cout << "~Line()" << endl;
}
void Line::setA(int x, int y)?
{
m_coorA.setX(x);
m_coorB.setY(y);
}
void Line::setB(int x, int y)
{
m_coorA.setX(x);
m_coorB.setY(y);
}
void Line::printInfo()
{
cout <<"("<<m_coorA.getX()<<","<<m_coorA.getY()<<")"<< endl;
cout <<"("<<m_coorB.getX()<<","<<m_coorB.getY()<<")"<< endl;
}
//Coordinate.h
#include <iostream>
#include <stdlib.h>
using namespace std;
class Coordinate
{
public:
Coordinate();
~Coordinate();
void setX(int x);
int getX();
void setY(int y);
int getY();
private:
int m_iX;
int m_iY;
};
//Coordinate.cpp
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include "Coordinate.h"
Coordinate::Coordinate()
{
cout <<"Coordinate() " <<m_iX<<","<<m_iY<< endl;
}
Coordinate::~Coordinate()
{
cout << "~Coordinate() "<<m_iX<<","<<m_iY<< endl;
}
void Coordinate::setX(int x)
{
m_iX = x;
}
int Coordinate::getX()
{
return m_iX;
}
void Coordinate::setY(int y)
{
m_iY = y;
}
int Coordinate::getY()
{
return m_iY;
}
2015-09-09
代碼貼一下唄