Using main.cpp and foo.cpp
Using main.cpp and foo.cpp
我为class制作了一个简单的程序,我发现了一个使用的程序示例
.h foo.cpp and main.cpp
我输入了那个程序,并使它编译得很好,但当我移动拆分我的程序时,我无法使它编译。
从其他.cpp
文件运行main方法的典型过程是什么?
这是我当前运行的程序,
main.cpp
#include <iostream>
#include "cars.h"
std::ostream& operator<<(std::ostream& s, const cars& c) {
return s << c.make << ' ' << c.model << ' ' << c.col << ' ' << c.wheels;
}
int main() {
cars c("Audi", "A4", "Black", "4");
cars q(c);
std::cout << c << 'n';
std::cout << q << 'n';
return 0;
}
如果我想创建一个cars.cpp
文件并将其拆分,那么我只在主方法中使用cout
,我在这里会遵循什么规则?
例如,我应该在main.cpp
中使用override
,还是应该将其移动到cars.cpp
?
我显然可以复制我找到的其他程序,但我想了解这一点。
同样不,这不是任务。我完成了,我想知道如何做到这一点,因为我是一个超级英雄,碰巧喜欢领先于其他人。
添加
extern std::ostream& operator<<(std::ostream& s, const cars& c);
在CCD_ 8中。
推动实施,
std::ostream& operator<<(std::ostream& s, const cars& c) {
return s << c.make << ' ' << c.model << ' ' << c.col << ' ' << c.wheels;
}
至CCD_ 9。
- 移动cars.cpp中的ostream运算符
- 在汽车中添加声明。h
- 在汽车中包含iostream.h
我想cars.cpp已经包括cars.h了?
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- Linux的Cpp上的计时器
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 命名空间中具有.h和.cpp文件的类
- 内置函数可查看CPP中的成员变量
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- Cpp-Tuple使用带有变量的get
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 有充分的理由在h文件中使用include保护而不是cpp文件吗
- 如何通过cpp程序运行shell脚本
- 使用2个键的cpp-stl::优先级队列排序不正确
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 如何在cpp文件之间切换窗口?在Qt中
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 我需要知道编译器如何在cpp中使用析构函数
- 用Microchip XC16编译器将foo.cpp构建为C代码
- FOO.tab.cpp较大项目的文件夹FOO部分中的文件.*.tab.cpp有什么特殊意义吗?
- Using main.cpp and foo.cpp
- 何时在foo.cpp中包含foo.h