Answer the question
In order to leave comments, you need to log in
How to correctly declare a function that uses a variable from a class, and a class that includes the use of this function?
I'll give an example:
//объявление функции
void someUniversalTool() {
int variable1 = someClass.variableInClass ;
//some additional code
}
//объявление класса
class someClass {
public:
void someClassTool() {
someUniversalTool();
//some additional code
}
int variableInClass = 5;
} Someclass someclass;
Answer the question
In order to leave comments, you need to log in
How to declare them in a way that avoids such errors?
class someClass {
public:
void someClassTool();
int variableInClass = 5;
};
Someclass someclass;
void someUniversalTool()
{
int variable1 = someClass.variableInClass ;
//some additional code
}
void SomeClass::someClassTool()
{
someUniversalTool();
//some additional code
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question