GUI Type Scope and Instantiation
Hello,
Sorry if this is a basic basic question.
I am familiar with doing console projects, but I am trying to do a gui project and the rules just don't seem to be the same.
I have two basic questions.
1) Why can I not include fstream and/or string headers in my gui project?
2) Why can I not instantiate variables outside of the WindowProcedure or the WinMain functions?
Below is some code with the error messages i received as comments.
The compiler does not complain about not being able to find the fstream/string headers, but yet it complains about not knowing the data type.Code:#include <windows.h> #include <iostream> #include <fstream> #include <string> #include "my.cpp" typedef struct county { int nType; }; class CYo { public: int xyz; }; int someint; CYo bob; CYoo alex;//defined in my.cpp county coul = {0};//no error string somestr;//error: `string' does not name a type fstream myfile;//error: `fstream' does not name a type someint=3;//error: expected constructor, destructor, or type conversion before '=' token bob.xyz = 4;//error: expected constructor, destructor, or type conversion before '.' token alex.xyz = 5;//error: expected constructor, destructor, or type conversion before '.' token coul.nType = 6;//error: expected constructor, destructor, or type conversion before '.' token LRESULT CALLBACK WindowProcedure {...};//header int WINAPI WinMain (..) { //standard window class and message pump } LRESULT CALLBACK WindowProcedure () { someint = 3;//no error bob.xyz = 4;//no error alex.xyz = 5;//no error coul.nType = 6;//no error //standard msg switch }
The compiler does not complain about my included data types.
The compiler does not like 'global' instantiation.
What is going on here?
Thanks,