C++ XCode C++;链接器命令失败,退出代码为1(使用-v查看调用)
我收到生成失败错误“链接器命令失败,退出代码为1” 我查看了其他论坛帖子,这些帖子谈到重复的函数调用会让链接器感到困惑。我没有太多的C++经验,所以我会很乐意帮忙的!p> ld:架构x86_64的1个重复符号 叮当声:错误:链接器命令失败,退出代码为1(使用-v查看调用) LINE.HC++ XCode C++;链接器命令失败,退出代码为1(使用-v查看调用),c++,xcode,linker,edit,C++,Xcode,Linker,Edit,我收到生成失败错误“链接器命令失败,退出代码为1” 我查看了其他论坛帖子,这些帖子谈到重复的函数调用会让链接器感到困惑。我没有太多的C++经验,所以我会很乐意帮忙的!p> ld:架构x86_64的1个重复符号 叮当声:错误:链接器命令失败,退出代码为1(使用-v查看调用) LINE.H #include <stdio.h> #include <string> using namespace std; class RuntimeException { // generi
#include <stdio.h>
#include <string>
using namespace std;
class RuntimeException { // generic run-time exception
private:
string errorMsg;
public:
RuntimeException(const string& err) { errorMsg = err; }
string getMessage() const { return errorMsg; }
};
// All that is needed for the special exceptions is the inherited constructor and method.
class EqualLines: public RuntimeException
{
public:
EqualLines(const string& err)
: RuntimeException(err) {}
};
class ParallelLines: public RuntimeException
{
public:
ParallelLines(const string& err)
: RuntimeException(err) {}
};
class Line {
public:
Line(double slope, double y_intercept): a(slope), b(y_intercept) {};
double intersect(const Line L) const throw(ParallelLines,
EqualLines);
double getSlope() const {return a;};
double getIntercept() const {return b;};
private:
double a;
double b;
};
#包括
#包括
使用名称空间std;
类运行时异常{//一般运行时异常
私人:
字符串errorMsg;
公众:
运行时异常(const string&err){errorMsg=err;}
字符串getMessage()常量{return errorMsg;}
};
//特殊异常只需要继承构造函数和方法。
类EqualLines:公共运行时异常
{
公众:
等值线(常量字符串和错误)
:RuntimeException(err){}
};
类ParallelLines:公共运行时异常
{
公众:
平行线(常量字符串和错误)
:RuntimeException(err){}
};
班级线{
公众:
直线(双斜率,双y_截距):a(斜率),b(y_截距){};
双相交(常数线L)常数投掷(平行线,
雌马);
double getSlope()常量{return a;};
双getIntercept()常量{return b;};
私人:
双a;
双b;
};
LINE.CPP
#include "line.h"
#include <iostream>
double Line::intersect(const Line L) const throw(ParallelLines,
EqualLines)
{
if (this->a == L.a && this->b == L.b)
{
throw "EqualLines";
}
else if (this->a == L.a)
{
throw "ParallelLines";
}
return (L.b - this->b) / (this->a - L.a);
}
#include "line.cpp"
#include <iostream>
int main()
{
Line L(2.0, 4.0);
Line K(3.0, 5.0);
try
{
if (L.getSlope() == K.getSlope() && L.getIntercept() == K.getIntercept())
throw EqualLines("The lines are equal: infinite intersection");
else if (L.getSlope() == K.getSlope())
throw ParallelLines("The lines are parallel: no intersection");
}
catch(EqualLines& zde)
{
}
catch(ParallelLines& zde)
{
}
cout << "Line 1: Y = " << L.getSlope() << "x + " << L.getIntercept();
cout << "\n";
cout << "Line 2: Y = " << K.getSlope() << "x + " << K.getIntercept();
cout << "\n\n";
L.intersect(K);
return 0;
}
#包括“line.h”
#包括
双线::相交(常数线L)常数投掷(平行线,
(马)
{
如果(本->a==L.a&&本->b==L.b)
{
扔“马”;
}
否则如果(本->a==L.a)
{
抛出“平行线”;
}
返回(L.b-此->b)/(此->a-L.a);
}
MAIN.CPP
#include "line.h"
#include <iostream>
double Line::intersect(const Line L) const throw(ParallelLines,
EqualLines)
{
if (this->a == L.a && this->b == L.b)
{
throw "EqualLines";
}
else if (this->a == L.a)
{
throw "ParallelLines";
}
return (L.b - this->b) / (this->a - L.a);
}
#include "line.cpp"
#include <iostream>
int main()
{
Line L(2.0, 4.0);
Line K(3.0, 5.0);
try
{
if (L.getSlope() == K.getSlope() && L.getIntercept() == K.getIntercept())
throw EqualLines("The lines are equal: infinite intersection");
else if (L.getSlope() == K.getSlope())
throw ParallelLines("The lines are parallel: no intersection");
}
catch(EqualLines& zde)
{
}
catch(ParallelLines& zde)
{
}
cout << "Line 1: Y = " << L.getSlope() << "x + " << L.getIntercept();
cout << "\n";
cout << "Line 2: Y = " << K.getSlope() << "x + " << K.getIntercept();
cout << "\n\n";
L.intersect(K);
return 0;
}
#包括“line.cpp”
#包括
int main()
{
第L行(2.0,4.0);
第K行(3.0,5.0);
尝试
{
如果(L.getSlope()==K.getSlope()&&L.getIntercept()==K.getIntercept())
抛出等高线(“直线相等:无限相交”);
else if(L.getSlope()==K.getSlope())
抛出平行线(“线平行:无交叉”);
}
渔获物(EqualLines和zde)
{
}
捕捉(平行线和zde)
{
}
cout在您的主文件中,您应该包含.h
文件,而不是.cpp请使用准确的错误消息编辑您的帖子。不要发布屏幕快照。错误消息应该指出链接阶段失败的原因。这不是回答问题。用户希望在此处使用另一个cpp文件。而不是标题f伊利