Advertisement

PLEASE HELP

Started by April 19, 2000 03:21 PM
14 comments, last by Anonymous Poster 24 years, 8 months ago
i defined a class in a header file, now i want to create a variable of this class: DrawQuad var; It works fine for now but when i try to access the variables objects, it stucks: var.a = 1; "a" is of course defined public. VC6 prints following error messages: error C2143: syntax error : missing '';'' before ''.'' error C2501: ''var'' : missing storage-class or type specifiers error C2371: ''var'' : redefinition; different basic types
i am the 2 between 0 and 1
I''m not completely sure, but make sure you have a semicolon at te end of your class definition. example:

class TRIANGLE
{
//whatever
}; <----semicolon
Advertisement
there is one !
do i have to declare the class somewhere since it is defined in the header. But i #include the header before i use the class !

any ideas ? please
i am the 2 between 0 and 1
Hmmm, it''s hard to tell from just that. Post a small snippet of code (including whatever you''re doing right before the line that breaks). It looks like it might be a syntax error on a previous line not getting detected until that point.

-Brian

You can get that error if you declare a variable of a type that''s not defined. Make sure you are including your class''s header file in the .cpp file you are using it in.

// CHRIS
// CHRIS [win32mfc]
ok here is the code:
ogl.h:

struct aabb
{
int a;
};


ogl.cpp:
#include "ogl.h"
aabb var;
var.a = 1;

thats it ! really !*g*
i am the 2 between 0 and 1
Advertisement
i tried to put the struct in the ogl.cpp too, and what happened ? the error came up again !

struct aabb
{
int a;
};

aabb abc;
abc.a = 1;


what am i doing wrong ???????????????? AAAAAAAAAAAAAAAAAAHHHHHHH PLEEEEEEEEASSE HELP!!!!!!!!!!!!!!! AAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHH
i am the 2 between 0 and 1
Take it easy... you are almost there...

Your problem is that you are trying to assign a value for that member of that class in no-where.

You should do the assignment in a global function like WinMain or in a member function of that class.

-Osmo

Edited by - Osmo Suvisaari on 4/19/00 4:44:33 PM
Maybe a silly question, but are you trying to set the class/struct members inside of a function? You can declare a variable globally, and in doing so call any of its constructors, but you can''t do anything else with it until you''re inside a function.

(oh, you can also assign a value to it in global scope, but I always get confused on the syntax for doing that with structs and arrays).

If you are in fact trying to do this within a function, something else is going on because what you''ve written should work.
I recommend the use of a member function, but here is anyway an modification of "ogl.cpp" that would compile:

#include "ogl.h"

aabb var;

void InitializeSomething()
{
var.a = 1;
}

This topic is closed to new replies.

Advertisement