本文介绍了分离定义和声明文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 自从我在C ++中做了很多工作以来已经有4年了。为了看我是否记得任何东西,我创建了一个新项目,创建了一个包含类的头文件,包含了我的主文件中的头文件,使用指针为用户指定的类实例动态分配内存,这很棒! 现在......我以前总是一定要分开我的定义和声明文件。我有什么在下面,它的工作原理,但我想有三个文件:main.cpp,animal.h和animal.cpp。我记得如何编码所有内容。它是预处理器指令,我似乎无法做对。但是,如果编译器出现问题,我会使用Bloodshed的Dev-C ++。 :-) main.cpp: 展开 | 选择 | Wrap | 行号 解决方案 我不确定你在问什么,但如果你想知道你是否放了一个#include" animal.h"在你的animal.cpp文件中,你做... 这基本上就是我要问的,但似乎我必须遗漏一些东西因为我得到这样的错误对于每个成员函数:36 C:\Dev-Cpp \ dispract \multifile classes \ animal.h`int animal :: animalCount''之前在此定义的。 我的头文件只有函数原型: 展开 | 选择 | Wrap | 行号 这是如此常见,我无法想象为什么我找不到啧啧orial就可以了。每个教程都在一个文件中执行所有操作以实现简单。 : - ( It''s been about 4 years since I did much in C++. To see if I remembered anything, I made a new project, made a header file containing a class, included the header file from my main file, used pointers to dynamically allocate memory for a user-indicated number of class instances, and it was great!Now... I used to always be sure to seperate my definition and declaration files. What I have is below and it works, BUT I would like to have three files: main.cpp, animal.h, and animal.cpp. I remember how to code everything. It''s the preprocessor directives I cannot seem to get right. However In case a compiler issue arrises, I use Bloodshed''s Dev-C++. :-)main.cpp: Expand|Select|Wrap|Line Numbers 解决方案 I''m not sure what you''re asking, but if you want to know if you put a #include"animal.h" in your animal.cpp file, you do...That''s basically what I''m asking, but is seems I must be missing something because I get an error like this for about every member function: "36 C:\Dev-Cpp\practice\multifile classes\animal.h `int animal::animalCount'' previously defined here".My header file just has the function prototypes: Expand|Select|Wrap|Line NumbersThis is so common that I can''t imagine why I can''t find a tutorial on it. Every tutorial does everything in one file for "simplicity". :-( 这篇关于分离定义和声明文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 03:51
查看更多