oop - Define a C++ class in 2 cpp files? -
Can I declare my class in 1 class and define 2 different CPP files? (like C #) Header: Source: and When I try to find a compiler error in the second CPP file "source file stdafx.h" (also "foo.h") can not open Yes you can. You can either do this, or disable the .cpp file using the precompiled header or your entire project. Ensure that you also use the Protector in your I agree @ paulm: dividing your implementation in this way is just an indication that your design is faulty, it is very rare that it is "right" The decision is that most of the time you should consider dividing your code into smaller, more manageable components.
The main reason is that I now have BTW all my headers "protected" to reduce the line number definition of my class in a single file. "+" Pragma onced ". "foo.h"
#pragma once #ifndef FOO_H_2014_04_15_0941 #define FOO_H_2014_04_15_0941 Square CFoo { Public: int plus (int a, int b); Int sub (int a, int b); }; #endif
"foo.cpp"
#include "stadafx.h "#include" foo.h "Int CFoo :: add (int a, int b) {return a + b; }
"foo2.cpp"
#include "stadafx.h" #include "foo.h" int CFoo :: sub (int a, int b) {return a - b; }
stdafx.h is a precompiled header file. This is a conference of Visual Studio, to optimize compilation, to put the frequently used header in
stdafx.h , then you include this file. You can should put
#include "stdafx.h" at the top of your source files.
foo.h file. Either, there is a series of preprocessor instructions in the form of Theodolis, or
#pragma once .
Comments
Post a Comment