0

Here is my code:

...
#include "myheader.h"

myClass::myStruct Foo;

Foo.one = 1;
Foo.two = 2;

myClass myclass(Foo);
...

This is my class from the header file:

class myClass : baseClass{
public:
struct myStruct {
myStruct():
one(0),
two(0){}
int one;
int two;
};
myClass(const myStruct &mystruct);
};

But this is failing to compile, I think I am accessing the elements one and two in the proper way... I get this error:

: expected constructor, destructor, or type conversion before '.' token .

Where a m I going wrong?

Codename
  • 452
  • 3
  • 15

1 Answers1

3
Foo.one = 1;

This is a statement, and it needs to go inside of a function or method definition. Statements cannot appear by themselves at the top level of a source file.

Try putting this code inside of a function, for example the entry point main():

int main() {
    myClass::myStruct Foo;

    Foo.one = 1;
    Foo.two = 2;

    myClass myclass(Foo);

    return 0;
}
cdhowie
  • 158,093
  • 24
  • 286
  • 300
  • I placed it the Init() that the file already has. The earlier error went away. But now, I have a new error : ISO C++ forbids declaration of myStruct with no type\n expected ';' before '.' – Codename Dec 29 '14 at 06:02
  • @Codename I can't see your screen. Show some code, preferably in a new question since this is a new issue. – cdhowie Dec 29 '14 at 06:03
  • http://stackoverflow.com/questions/27684721/iso-c-forbids-declaration-of-mystruct-with-no-type – Codename Dec 29 '14 at 07:05