if I have a class with the public variables int variable1 and bool variable2, how would I return that
like this? return {int something,bool something};
You don't return 'classes'. You return 'objects' of the 'class type'. The 'thing' listed prior to the function name is the 'return type' of the function. If you are going to return a variable of type int or an int 'literal'(e.g. 1, 100, 30), you put int in front of the function name. If you are going to return an object of your class, you put the class name in front of the function name. Then, inside the function, you return a variable of your class type:
Code:
class Apple
{
public:
int num;
double size;
Apple(int n, double d)
{
num = n;
size = d;
}
};
Apple func(void)
{
Apple my_apple(10, 3.5);
return my_apple;
}
int main()
{
Apple a = func();
cout<<a.num<<endl;
cout<<a.size<<endl;
return 0;
}