| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 650 人关注过本帖
标题:小白在自学C++,练习题调试无能求解救
只看楼主 加入收藏
张嘉纹
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-8-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
小白在自学C++,练习题调试无能求解救
题目是关于线段的类,由键盘输入线段端点的坐标,返回线段起始点坐标和线段长度。然而初学不知道怎么搞得,在VS运行一堆问题= =
1>Line.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Point::~Point(void)" (??1Point@@QAE@XZ),该符号在函数 __unwindfunclet$??0Line@@QAE@XZ$0 中被引用
1>test.obj : error LNK2001: 无法解析的外部符号 "public: __thiscall Point::~Point(void)" (??1Point@@QAE@XZ)
1>Line.obj : error LNK2019: 无法解析的外部符号 "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Point::ToString(class Point const &)const " (?ToString@Point@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV1@@Z),该符号在函数 "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Line::ToString(class Line const &)const " (?ToString@Line@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV1@@Z) 中被引用
1>Line.obj : error LNK2019: 无法解析的外部符号 "public: double __thiscall Point::Distance(class Point)" (?Distance@Point@@QAENV1@@Z),该符号在函数 "double __cdecl Length(void)" (?Length@@YANXZ) 中被引用
1>test.obj : error LNK2019: 无法解析的外部符号 "public: double __thiscall Line::Length(void)const " (?Length@Line@@QBENXZ),该符号在函数 _main 中被引用
1>test.obj : error LNK2019: 无法解析的外部符号 "public: double __thiscall Point::X(void)const " (?X@Point@@QBENXZ),该符号在函数 _main 中被引用
1>test.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall Point::Y(double)" (?Y@Point@@QAEXN@Z),该符号在函数 _main 中被引用
1>test.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall Point::X(double)" (?X@Point@@QAEXN@Z),该符号在函数 _main 中被引用
1>D:Level3\HW\2.3.5\Debug\2.3.5.exe : fatal error LNK1120: 7 个无法解析的外部命令

// Point.hpp

#ifndef Point_HPP
#define Point_HPP

#include <iostream>
using namespace std;

class Point
{
private:
    double x;    // X coordinate
    double y;    // Y coordinate

public:
    // Constructors
    Point();                                // Default constructor
    Point(double xval, double yval);        // Initialize with x and y value
    ~Point();

    // Accessing functions
    double X() const ;                    // The x-coordinate
    void X(double newX);
    double Y() const;                    // The y-coordinate
    void Y(double newY);

    string ToString(const Point &pt)const;//a string description of the point
    double Distance(const Point p);//Calculate the distance between two points

};



#endif

// Line.hpp
//
// (Finite) line segments in 2 dimensions. This class represents an undirected
// line segment.

#ifndef Line_HPP
#define Line_HPP

#include <iostream>
#include "Point.hpp"
using namespace std;

class Line
{
private:
        
        Point startPoint;    // e1
        Point endPoint;        // e2

public:

    // Constructors
    Line();                                    // Line with both end Points at the origin
    Line(const Point &p1, const Point &p2);    // Line with end Points [p1, p2]
    Line(const Line &l);                 // Copy constructor
    virtual ~Line();                            // Destructor

    // Accesssing functions, point getter
    Point start() const;                           
    Point end() const;                                

    // Modifiers, point setter
    void start(const Point& pt);                    // Set Point pt1
    void end(const Point& pt);                        // Set Point pt2

    string ToString(const Line &l)const;//a string description of the line
    double Length() const;//the length of the line
};

#endif

//Line.cpp

#include<iostream>
#include<sstream>
#include <cmath>
#include "Line.hpp"

Point::Point():x(0),y(0)
{

}

Line::Line()
{

}

Line::~Line()
{
   
}

Line::Line(const Point& p1, const Point& p2)
{
    startPoint=p1;
    endPoint=p2;
}

Line::Line(const Line& l)
{
    startPoint=l.startPoint;
    endPoint=l.endPoint;
}

Point Line::start() const
{
    return startPoint;
}

Point Line::end() const
{
    return endPoint;
}

void Line::start(const Point& pt)
{
    startPoint=pt;
}

void Line::end(const Point& pt)
{
    endPoint=pt;
}

string Line::ToString(const Line &l)const
{
    stringstream ss;
    ss<<"Start Point:"<<start().ToString(startPoint)<<"End Point"<<end().ToString(endPoint);
    return ss.str();
}

double Length()
{
    double d;
    const Line l;
    d=l.start().Distance(l.end());
    return d;
}

// Testpoint.cpp

#include <iostream>
#include "Line.hpp"
using namespace std;
   
int main()
{
    double x1,y1,x2,y2;
    cout<<"enter the coordinates of the start point and end point respectively:\n";
    cin>>x1;
    cin>>y1;
    cin>>x2;
    cin>>y2;
    // Create a point
    Point p1,p2;
    p1.X(x1);
    p1.Y(y1);
    p2.X(x2);
    p2.Y(y2);
    double d = p1.X();
    // Linesegment
    Line L1(p1, p2);
    //cout<<"The description of the line: "<<L1.ToString(L1)<<endl;
    cout<<"The length of the line is: "<<L1.Length()<<endl;
    return 0;
}
搜索更多相关主题的帖子: 练习题 public 键盘 
2015-08-04 23:10
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:10 
你的是多文件工程,我懒得建工程大致看了一下,你没有加string类所在的头文件,而且头文件调用也有问题。

一片落叶掉进了回忆的流年。
2015-08-05 08:49
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:10 
Point.cpp 在哪里?
2015-08-05 08:57
快速回复:小白在自学C++,练习题调试无能求解救
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019927 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved