void bar(person person1)//person was not declared.
is this really possible, I think bar() would not recognize "person" and if let's say it does recognize then concept of global is nothing all things inside functions are all globals
If you are going to use a struct/class as a function parameter or return type you have to declare as global either outside main or in a header you include in your main file. Having a local struct/class inside a function would be pointless as it would go out of scope as soon as the function ends. You could do something like this, but I think it is rather silly to do so:
#include <iostream>
#include <string>
usingnamespace std;
void foo(string &name, int &age)
{
struct Person{
string name = "Danicpp";
int age = 27; // sorry just a random number
};
Person person1;
name = person1.name;
age = person1.age;
}
int main()
{
int number;
string strTest;
foo(strTest, number);
cout << strTest << " .::. " << number << endl;
return 0;
}
Yeah, that isn't possible and the compiler shouldn't compile it at all. He deleted his account so I have no clue why he put that other than maybe to demonstrate that it isn't possible to do it.