I\'m trying to access a member structs variables, but I can\'t seem to get the syntax right. The two compile errors pr. access are: error C2274: \'function-style cast\' : i
Bar
is inner structure defined inside Foo
. Creation of Foo
object does not implicitly create the Bar
's members. You need to explicitly create the object of Bar using Foo::Bar
syntax.
Foo foo;
Foo::Bar fooBar;
fooBar.otherdata = 5;
cout << fooBar.otherdata;
Otherwise,
Create the Bar instance as member in Foo
class.
class Foo{
public:
struct Bar{
int otherdata;
};
int somedata;
Bar myBar; //Now, Foo has Bar's instance as member
};
Foo foo;
foo.myBar.otherdata = 5;