#VS2015中并未包含Sales_item.h这个头文件,需要自行去http://www.informit.com/store/c-plus-plus-primer-9780321714114下载
方法:点击Downloads,选择 Download the source code files for MS Visual Studio 2012 ,下载,得到的 VisualStudio2012.rar 包括本书的所有所含代码
解压,将文件夹1中的Sales_item.h复制到项目文件夹中,这样就可以 #include "Sales_item.h" 了
参考自:《C++ Primer 第五版 中文版》 P20 1.5.1节练习
#添加完毕,编译,发现错误: 无法打开包括文件: “Version_test.h”
发现还得将VisualStudio2012文件夹中的 version_test.h 头文件复制到项目文件中才行
参考自:https://bbs.youkuaiyun.com/topics/390793647 9楼
P.S:不知道是不是所有本书代码/头文件都需要此头文件
#再编译,又有错误:1>math.h(509): error C2375: “lround”: 重定义;不同的链接
1>version_test.h(74): note: 参见“lround”的声明
也许是编写错误,这里需要将 version_test.h 中的
#ifndef lround
inline long lround(double d)
{
return (d >= 0) ? long(d + 0.5) : long(d - 0.5);
}
#endif
改为
#ifdef lround
inline long lround(double d)
{
return (d >= 0) ? long(d + 0.5) : long(d - 0.5);
}
#endif
也就是把第73行的#ifndef改为#ifdef
具体原理我也不清楚啦~~~
参考自:https://blog.youkuaiyun.com/yeeff/article/details/81172440