Thread: classes in windows programming

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    classes in windows programming

    i dont know how to search for a solution for this, so i'll make a new topic for it. first poster

    anyway. i have 2 programs, both made in C, only one is windows programming, using win API and all that, the other is a console project.

    in the console program i made my own classes, and it all worked fine.
    in the windows program, the exact same definition of the class as in the console program, doesn't work, as VStudio drops me a lot of syntax errors about the class definition.

    now, my question is: does defining classes when programming windows work differently, or it doesn't work at all ? =/


    Code:
    class character {
    private:
    	int num;
    	char name[30];
    public:
    	//methods
    };
    this passes ok when building a console project.
    but when i put this in a .c file which has the WinMain() function and everything else related, i get these syntax errors:
    Code:
    d:\my docs\Visual Studio Projects\struja_igra\strukture.h(15): error C2061: syntax error : identifier 'character'
    d:\my docs\Visual Studio Projects\struja_igra\strukture.h(15): error C2059: syntax error : ';'
    d:\my docs\Visual Studio Projects\struja_igra\strukture.h(15): error C2449: found '{' at file scope (missing function header?)
    d:\my docs\Visual Studio Projects\struja_igra\strukture.h(15): error C2059: syntax error : '}'
    and so on. anyone got any advice for this ? thx

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You are writing C++ code, but compiling as C. So it is not a matter of programming for Windows, but trying to pretend that C++ code is C code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    2
    so i cant define classes in C code ? o0

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    so i cant define classes in C code ?
    Yes. You can define structs, but C structs are a subset of C++ structs (which are pretty much equivalent to C++ classes).

    The good news is that you can mix C and C++, so you do not have to restrict yourself to programming in C. Read this FAQ on How to mix C and C++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  2. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  3. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM

Tags for this Thread