N
N
Nikita2022-04-12 10:21:20
C++ / C#
Nikita, 2022-04-12 10:21:20

Is it a good solution to split a large class into multiple .cpp files (C++)?

Let's say I have an Example class . Its header is declared in the Example.hpp file . But if I create an Example.cpp file (as is usually done) and write in it the implementation of all the functions declared in the Example.hpp file , then the resulting file can grow to several thousand lines, which is not very readable.

Is something like this a good solution?

Example

Example.hpp - заголовок класса
Task1.cpp - реализация функций класса, посвященных задаче Task1
Task2.cpp - реализация функций класса, посвященных задаче Task2
Task3.cpp - реализация функций класса, посвященных задаче Task3
Task4.cpp - реализация функций класса, посвященных задаче Task4
.
.
.
.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Adamos, 2022-04-12
@gth-other

Before the advent of the IDE, this could be considered a solution.
Now - no one needs and even an interfering crutch.
Actually, a class for thousands of lines is not a problem in itself.
But the fact that I want to scatter it over five files is a clear hint that refactoring is required to simplify the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question