Answer the question
In order to leave comments, you need to log in
Calling a function from a class?
I want to call the getValues function from the Properties class . Unfortunately, I can not understand the error that is happening ... Who knows, write any option. Plizz)
I will also correct the code.
#include <iostream>
class Properties
{
public:
int a = 13;
int b = 82;
float c = 27.01f;
void getValues(Properties* objectValues);
};
void Properties::getValues(Properties* objectValues) // именно эту...
{
std::cout << objectValues->a << std::endl;
}
int main()
{
setlocale(0, "");
Properties* objectValues;
objectValues->getValues(); // неужели так нельзя?
std::cin.get();
return 0;
}
Answer the question
In order to leave comments, you need to log in
You have an error in calling the getValues method because an argument is expected: void getValues(Properties* objectValues);
.
Create an object and pass a reference to it.
Properties obj;
Properties* objectValues = new Properties;
objectValues->getValues(&obj);
#include <iostream>
class Properties
{
public:
void getValues();
int a = 13;
int b = 82;
float c = 27.01f;
};
void Properties::getValues()
{
std::cout << a << std::endl;
}
int main()
{
setlocale(0, "");
Properties* ptr = new Properties;
ptr->getValues();
std::cin.get();
return 0;
}
#include <iostream>
class Properties
{
public:
void getValues();
int a = 13;
int b = 82;
float c = 27.01f;
};
void Properties::getValues()
{
std::cout << a << std::endl;
}
int main()
{
setlocale(0, "");
Properties obj;
obj.getValues();
std::cin.get();
return 0;
}
I think you have an error in the method signature. You do not need to pass a pointer there, you need to take data from this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question