I usually code in Java, but I have started to learn c++ as I'm trying to get into some competitive programming. What is confusing for me right now is that in java you can declare a method within a class, make it public and thats that.
For example, in Java:
public class Main{
public int javamethod(int myNum){
return myNum;
}
}
Whereas in C++, you split the function declaration and definition into different files (like cprogram.hpp and cprogram.cpp). Isn't this redundant and repetetive? What exactly is the point of this?
C++ example (header file)
int cppfunc(int myNum);
(cpp file)
int cppfunc(int myNum){
return myNum;
}