+ 2
What advantage or disadvantage of writing program in 3 file structure in c++ than writing program in 1 file in c++?
I would like to know what will be the difference if i write a program using 3 file structure in c++.i am beginner in c++.
6 ответов
+ 4
Large projects can contain thousands if not millions of lines of code. seperating classes into files helps make managing the code base much easier. But as Jason stated. It makes no difference to the final program
+ 3
the main advantage of using different files for different classes is that you can edit individual classes without having to touch the main operating files. Ultimately it doesnt make a difference to the final executable.
+ 3
well. there is main.cpp which is the entry point of the program.
when you create a class (lets say we are making a class called animal) you seperate the definition and methods into seperate files a .h header file (animal.h) and a .cpp file (animal.cpp)
animal.h would contain something like this
class animal()
{
public:
animal();
void speak();
private:
string m_name;
}
animal.cpp would look something like this
#include "animal.h"
animal::animal():
name("fred")
{
}
void animal::speak()
{
cout << "I am " << m_name;
}
+ 1
Further explaination is appreciated
0
Thanks i was thinking it will take less time to execute when the program is written in 3 file structure.
0
Thanks my confusion is clear... Thanks again.