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 #)
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 ".

Header: "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   

Source: "foo.cpp"

  #include "stadafx.h "#include" foo.h "Int CFoo :: add (int a, int b) {return a + b; }   

and "foo2.cpp"

  #include "stadafx.h" #include "foo.h" int CFoo :: sub (int a, int b) {return a - b; }   

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.

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.

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 foo.h file. Either, there is a series of preprocessor instructions in the form of Theodolis, or #pragma once .


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.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -