|
-
June 11th, 2008, 08:24 PM
#1
GUI Type Scope and Instantiation
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.
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 not being able to find the fstream/string headers, but yet it complains about not knowing the data type.
The compiler does not complain about my included data types.
The compiler does not like 'global' instantiation.
What is going on here?
Thanks,
-
June 13th, 2008, 09:06 AM
#2
Re: GUI Type Scope and Instantiation
Well first of all, u need to add:
Code:
using namespace std;
to get fstream etc to work.
Global variables should be fine, thats now a problem.
It's a good convention NOT to include .cpp files.
Using .h files instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|