I also understand what header files and classes in general. That I cannot get an implementation when to use a header or class? Do I have to create classes for everything I do? Do I need my actual work functions? be in header files or in CPP files? I am lost in the correct use of these and may use some kind of guidance in the real world from more experienced programmers.
Repeat for several years, and I would have the same question - this is not something that is very well covered, I don’t think. So let me break the part that I see as the meat of your problem.
Do I need to create classes for everything I do?
, , . , , . , , C, int char. String STL ( ). , , , , , , , - -.
, .
, . , C , , C++ , ( , ). :
#include <iostream>
using namespace std;
int testadd()
{
int a = 4; int b = 2; int c = add(a, b);
return c;
}
int add(int x, int y)
{
return x + y;
}
int main(int argc, char** argv)
{
cout << "result is: " << c << endl;
return 0;
}
( ) , testadd add, main add.
, , , . - , , , , ( ), . .
, , :
, . 1, , , , , .
, , 1, , main.cpp, myclass.h, myclass.cpp myclass, myclass.cpp main.cpp, , , (*.cpp) (main.obj myclass.obj vc). , exe, ), , , . , exe. , . ( ), .