class - Does the order of declaring functions and methods in C++ matter -
in c when use function before declaring compiler assumes takes no parameters , returns , int.
if function returns type or takes parameters compiler produces error.
same happen in c++ if make object of class declared later on in code?
the order matter. if reference function has not been declared (just signature , return type, no implementation) compiler throw error. definition of function can wait until link time. afaik, there not implicit declaration in c++.
usually put declarations of functions in header files. traditionally, symbols exported translation unit (usually stand-alone source file e.g., hello.cpp
) made available through similarly-named header file (e.g., hello.h
). implementation follows in source file. every translation unit can include header files other translation units (e.g. other.h
).
every translation unit gets compiled individually (i.e. source file such hello.cpp
; #include
preprocessing statements replaced actual contents of files included). @ link time, implementations of functions in different translation units linked together. if linking step fails, can still encounter errors.
Comments
Post a Comment