Stumped. Trying to pass a struct variable to class member function. Get syntax error as the struct variable is not being passed to the class function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
using namespace std;
class Example
{
public:
void foo(St1 var)
{
}
};
struct St1
{
int x, y;
};
int main()
{
Example e1;
St1 s1;
s1.x = 3; s1.y = 6;
e1.foo(s1);
return 0;
}
// Errors given:
// Syntax error: identifier 'St1'
// 'Example::foo': function does not take 1 argument
|
Last edited on
Define your struct BEFORE your class definition.
And PLEASE, learn to use code tags, it makes reading your source much easier.
http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post and add code tags.
Thank you very much!!
Last edited on