What's more correct,
Option #1
-----------------------------------------------------------------------------------
Dog.h
ref class Dog
{
public:
Dog(void);
void Bark();
void Poop(System::Int32^ HowMuch);
};
Dog.cpp
#include "Dog.h"
Dog::Dog(void)
{
// some code
}
void Dog::Bark()
{
// some code
}
void Poop(System::Int32^ HowMuch)
{
// some code
}
Option 2
------------------------------------------------------
Dog.cpp
ref class Dog
{
public:
Dog(void)
{
// some code
}
void Bark()
{
// some code
}
void Poop(System::Int32^ HowMuch)
{
// some code
}
};
I prefer using option #1, keeping my declarations on the header file and then including it on the main source file rather than writing everything on a cpp source file and then include it on the main cpp file.The problem comes when trying to use features like properties, how the hell do you use properties using option #1 When i try it the compiler throws me errors left and right, i'm new to C++/CLI so bare with me ;)
Is even necessary to have headers with C++/CLI, i mean, 100% managed code When to use them
Thanks,
Daniel

C++/CLI and Headers
js06
Question 1:
option 1, in general, is better for some reasons:
- Keep header files clean for reading since these represent the interfaces of the project.
- Keep header files short and the parser and compilation will be faster.
- If you all the code in the .h and you have to change a method that could be in the .cpp, all the files that depend on your header will get compiled.
(maybe more reasons but I can't remember any more at this moment :S)
Question 2:
in .h:
ref class Dog
{
private: int myInt;
public: property int MyInt { int get(); void set(int value); }
};
in .cpp:
int Dog::MyInt::get() { return myInt; }
void Dog::MyInt::set(int value) { myInt = value; }
Question 3:
You don't need to use 100% managed code, although if your project targets the .net platform and you don't need to use classes in other projects and don't want to worry about memory leaks, then you can do it all in managed code. C++ classes allow you to use them in other projects if needed. You also have the responsability of creating and deleting instances of these classes instead of letting the garbage collector do all the work automatically.
Hope this answers your questions.