The class code is fully described, but lower than the method call from this class. In fact, I have a truck that should be able to add itself to the loading queue at the base, and the base should be able to remove this truck from the queue after a number of frauds.
- for a class, you can use a preliminary declaration and use this preliminary declaration to declare a pointer or a link to an instance of a class, as well as for inline methods of another class that will not use the "." and "->" from a link or pointer, respectively, does not work this way for functions, generally a strange question, as if you intend to declare different functions and classes in one hider, which is not particularly correct. - OlegUP
3 answers
Declare a class and its methods before the place where they are used. And determine after.
Class declaration :
class class_name { void method1(); };
Method definition :
void class_name::method1() { // код метода }
In practice, individual classes are declared in class_name.h
( class_name.h
), and methods are defined in class_name.cpp
. To add a class_name
to another file, use the preprocessor include
command:
#include "class_name.h"
I’ll add the user Andrey in response. First, it’s better to write the class name with a capital letter, and secondly, it’s advisable to write specifiers (public, protected, private), although it’s not necessary, the default is private, I just think that your method will be called by the client accordingly, it should not be private, but public:
class ClassName { public: void method1(); };
- oneFrom which letter to write - large or small - depends on the style adopted in the team / company / project. - andrybak
- oneAbout public / private - the remark is correct. And about the register of beech, Andrew has already answered - this is a matter of style, personal or corporate. - skegg
for a class, you can use a preliminary declaration and use this preliminary declaration to declare a pointer or a link to an instance of a class, as well as for inline methods DEFINED within the definition of another class that will not use the "." and "->" from a link or pointer, respectively, does not work this way for functions, generally a strange question, as if you intend to declare different functions and classes in one hider, which is not particularly correct.
class Foo; class Bar { private: Foo* foo_; public: void setFoo( Foo* foo ) { // inline метод foo_ = foo; } };
After a preliminary declaration, you can include a header with a full definition of the Foo class in the .cpp file for the Bar class methods