people.h文件中的People类构造函数没有函数体

#ifndef PEOPLE_H
#define PEOPLE_Hclass People
{public:void setHeigth(double len);double geHeigth(void);People(); // 这是构造函数
private:double length;
};
#endif

people.cpp文件中的实现了People类构造函数

#include <iostream>
#ifndef PEOPLE_H
#include "../include/people.h"
#endifusing namespace std;// 头文件中的函数必须实现,不然会报 undefined reference to `People::People()'的错误
People::People(void)
{cout << "Object is being created" << endl;
}void People::setHeigth(double len)
{length = len;
}double People::geHeigth(void)
{cout << "Object is being created" << endl;return 1.8;
}

Cplus_cons_test.h文件中Line类中有一个数据成员People,必须包含people.h文件。

#ifndef CPLUS_CONS_TEST
#define CPLUS_CONS_TEST#include "people.h"typedef unsigned char FX_BYTE;
typedef const char *FX_LPCSTR;class Line
{public:void setLength(double len);double getLength(void);Line(); // 这是构造函数//People a();private:double length;People people_p;
};#endif

Cplus_cons_test.cpp文件中如果没有#include "people.cpp"这句而People类的构造函数没有函数体(也就是没有花括号‘{}’),链接时会报undefined reference to `People::People()'的错误。

#include <iostream>
#include "../include/Cplus_cons_test.h"/*** 这句包含非常重要,如果没有这句会报undefined reference to `People::People()'*/
#include "people.cpp"using namespace std;// 头文件中的函数必须实现,不然会报 undefined reference to `Line::Line()'的错误
Line::Line(void)
{cout << "Object is being created" << endl;
}void Line::setLength(double len)
{length = len;// double l = People::geHeigth();
}double Line::getLength(void)
{return length;
}

main.cpp

#include <iostream>
#include "../include/Cplus_cons_test.h"using namespace std;// 程序的主函数
int main()
{Line line;// 设置长度line.setLength(6.0);cout << "Length of line : " << line.getLength() << endl;system("pause");return 0;
}

链接时undefined reference to构造函数相关推荐

  1. [ c++] cmake 编译时 undefined reference to `std::cout‘ 错误的解决方案

    [ c++] cmake 编译时 undefined reference to `std::cout' 错误的解决方案 参考文章: (1)[ c++] cmake 编译时 undefined refe ...

  2. Linux下载源码编译出错,linux下fortran中编译代码时“undefined reference to `_gfortran_st_”错误...

    在linux系统下fortran与c/c++混合编译的时候出现下列的错误: /mnt/hgfs/subrar/ts/src/extra/../SAVE_DATAQ.f:117: undefined r ...

  3. 交叉编译时undefined reference to `inflate_魅蓝风采现腕间 品鉴格拉苏蒂原创议员系列世界时腕表...

    [腕表之家 腕表品鉴]德国品牌一向以高超的技术作为自己的立身之本,而格拉苏蒂原创作为德国腕表品牌,它具有鲜明的德国特色,秉承锐意创新的价值理念.这款Senator Cosmopolite 议员世界时腕 ...

  4. GCC 链接时出现undefined reference to “...”时可能解决办法

    undefined reference to "..." 顾名思义就是没找到,没找到的原因有两个 1.不存在.不存在就想办法加进去. 2.找错地方. GCC链接时的特点是按顺序连接 ...

  5. openjpeg:解决静态链接时未定义引用错误:undefined reference to `__imp_opj_xxxxxxx'

    解决办法 加入OPJ_STATIC宏定义. 1. 在#include "openjpeg-2.1/openjpeg.h"之前中加入OPJ_STATIC定义,如下 #ifndef O ...

  6. Eclipse编译时函数报错:Undefined reference to 'pthread_create'

    Eclipse + CDT: pthread_create函数编译时报错:undefined reference to `pthread_create' undefined reference to ...

  7. 解决caffe编译时//usr/lib/x86_64-linux-gnu/libSM.so.6: undefined reference to `uuid_unparse_lower@UUI

    我在编译安装RefineDet的caffe版遇到//usr/lib/x86_64-linux-gnu/libSM.so.6: undefined reference to `uuid_unparse_ ...

  8. Linux下链接库出现的undefined reference问题总结

    1.链接时缺失了相关目标文件(.o) 测试代码如下: 然后编译. 01. gcc -c test.c 02. gcc -c main.c 得到两个.o文件,一个是 main.o,一个是test.o,然 ...

  9. linux下编译自己的静态库时依赖其他的动态库,使用时出现“undefined reference to”

    对于我这个刚入IT行业不就得新手来说,在linux下链接库的时候总是会遇到各种各样奇葩的问题,最多的就是"undefined reference to"和"cannot ...

最新文章

  1. scala入门之识别函数式风格
  2. css之object-fit
  3. Android踩坑日记:Android动态权限分析和解决方案
  4. vue2.0 子组件和父组件之间的传值
  5. java azure blob 查询_快速入门:适用于 Java 的 Azure Blob 存储客户端库 v8 | Microsoft Docs...
  6. OC基础之访问修饰符
  7. java 编译 器 ide_在没有IDE的情况下编译和运行Java
  8. 【Android优化篇】提升Activity加载速度的方法
  9. win11快捷键怎么使用 Windows11快捷键的使用方法
  10. poj 2987 Firing (最大权 闭合 图)
  11. 成都Uber优步司机奖励政策(1月26日)
  12. 游戏平台系统源码有多重要?
  13. 数据结构入门指南(C语言版)
  14. bigemap软件优势
  15. 28个超有用的PPT小技巧,快来收藏
  16. termux搭建局域网web服务器
  17. python dataframe重新索引_Concat DataFrame重新索引仅对唯一值索引对象有效
  18. 关于不同操作系统下浏览器兼容问题
  19. 根据判断PC浏览器类型和手机屏幕像素自动调用不同CSS
  20. 维基百科诞生,它是一个自由、免费、内容开放的网络百科全书,是世界第五大网站...

热门文章

  1. plsql连接不上64位oracle,plsql develope连接64位Oracle 11g出错解决方案(图)
  2. html上的样式 ui vant_解决vue中组件库vant等ui组件库的移动端适配问题
  3. bool变量取反_Task 01:Python基础入门:从变量到异常处理(第1天)
  4. 性能服务器解读,【MySQL数据库】第三章解读:服务器性能剖析(上)
  5. 隔板都被拉去做核酸了?
  6. 偷走不经意流逝的时光,摸鱼神器:神偷
  7. 知乎热议:计算机专业钱景究竟如何?
  8. 那些实用与颜值齐飞的桌面!
  9. 星巴克在GitHub中泄漏API密钥,发现者获4000美金奖励
  10. 解决原子性问题?你首先需要的是宏观理解