C2084
-
error C2084: function 'void __thiscall Stock::setNumOfOutShares(int &)' already has a body thank you ! :((
If you have implemented the function in a file header, you will need to add 'inline' to the beginning of you function declaration, otherwise move the function implementation to a .cpp file.
-
If you have implemented the function in a file header, you will need to add 'inline' to the beginning of you function declaration, otherwise move the function implementation to a .cpp file.
can you please tell me how do i write a regular class ? i did not have this problem be4 but when i put the class definitions(those were my .cpp files), i added them to my class declarations (.H files) i got hundreds of errors C2084?? can you tell please tell me what is the right way to write classes? and what do you mean by add 'inline'to the beginnig to the function? can you give an example? thank you so much
-
can you please tell me how do i write a regular class ? i did not have this problem be4 but when i put the class definitions(those were my .cpp files), i added them to my class declarations (.H files) i got hundreds of errors C2084?? can you tell please tell me what is the right way to write classes? and what do you mean by add 'inline'to the beginnig to the function? can you give an example? thank you so much
There are a number of ways to write a class. I think that how you do it depends on the current situation. Alot of times programming style simply depends on your tastes. I have developed code with alot of other people, and they all like to organize their classes in their own ways. One thing to keep in mind though, is that alot of people may see your header files if they are going to use your classes, the implementation files are rarely ever seen. With this in mind, the code that you do not want other people to see should be placed in the .cpp file. If you have a large class with complicated implmentations I would create a header file with the class and function declarations, then place the implementations in the .cpp file. If you class has a lot of simple get and set functions, these are good candidates for inline functions. For instance:
class Stock { CHAR* GetName () { return name; } };
or like I suggested earlier, add the inline declaration to the function implementation.class Stock { CHAR* GetName (); }; inline CHAR* Stock::GetName () { return name; }
inline functions will make the entire piece of code that is created for the function will be compiled inline where the function would normally be called instead of actually calling the function. The only drawbacks to inline functions is that if you do it too often, the size of your program will become bloated. Use function inlining judiciously. The reason why you get a million errors with out the inline declaration, is because every file that includes your header file recompiles the functions that should be declared inline, and when the linker tries to link all of these files it finds multiple implementations for the function. Using inline forces only one implementation.