CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2008
    Posts
    21

    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,

  2. #2
    Join Date
    Aug 2003
    Posts
    938

    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
  •  





Click Here to Expand Forum to Full Width

Featured