• Advertisement

Archived

This topic is now archived and is closed to further replies.

PLEASE HELP

This topic is 6515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
I''m not completely sure, but make sure you have a semicolon at te end of your class definition. example:

class TRIANGLE
{
//whatever
}; <----semicolon

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanx ! It helps !
i did it as you said, Osmo Suvisaari, thanx alot !!!!!

But i have another question !

How can i add a elemnt to a array without deleting the array. For Example i have int a[3] how can i change this at runtime in int a[4] ?
i know its something with dynamic memory things. iam new to this.

Share this post


Link to post
Share on other sites
You can''t. Not the way you want to at least. When you declare an array, the memory is set aside at compile time, unless you use dynamic memory allocation like new or malloc. So, you either need to delete the old memory and make a new block for the array (''Cause there''s no gaurantee that the next address is free, this is neccessary, otherwise you''ll overwrite your memory bounds) or you can make an array large enough to hold all of the values you think you''ll ever need.

You could look into the STL classes though. One of those would probably work. It has classes that simulate what you want to do.

If not you, could build you own linked list, it''s not to hard once you get your mind around it and there are tons of free samples on the net.

Share this post


Link to post
Share on other sites
I made a liked list. What you do is make a struct that has a pointer to the next item in the list. You can also add a pointer to the previous item.

struct NODE
{
NODE next;
void *data;
};

Where the pointer to data can be anything you really want. (I used my list to keep track of images that are in memeory, they need to be all deallocated upon exit)

Now you need a function that will add a node to the list, what you do is have a loop that searches till it finds the last node (or you can have a variable to store the pointer to the last node) and attaches a new node to the list.

void addNode( NODE *list, NODE *new )
{
// I use NULL to signify end of list
while( list != NULL ) // loop while not the last element
list = list->next; // set to next element
list->next = new; // set next element to new
new->next = NULL; // make new last element
}

Now you will probably want a function to remove an item from the list, this is a similar fucntion.

void removeNode( NODE *list, NODE *target )
{
NODE *next;
while( list != NULL )
if( list->next == target ) // if we found target
break; // end search
else
list = list->next; // else contine with search
if( list == NULL ) // last node, no match
return;
next = target->next; // save the pos of the next node
list->next = next; // link the list
delete target; // destroy target
}

Note that you will have to only keep track of a pointer to the first node externally. The benefits of this is that you can make the list as long or short as you want by adding in nodes or removing them. However this is lower than having a prediefined array as if you want to get the 5th item you have to do a for loop. In the for loop you have to have an if statement to make shure you wont be using a NULL to point to the next item. (ie you have 4 nodes and you want to access the 5th)

You could do an array of pointers to arrays of pointers to the data. That would put a limit but it would be high, and you could always keep some pointers NULL therfore not waste memory. Sound confusing? Should be, I can bearly imagne it.

OneEyeLessThanNone
- Gonna pluck whichever Eye I have left. Keeps itching

oh btw, could somone tell me if my code would mess up upon removing nodes? I wrote this off the top of my head and the linked list i used took asome debugging to fix. (forgot to change the list pointer when removing first item LOL)

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

How can i add a elemnt to a array without deleting the array. For Example i have int a[3] how can i change this at runtime in int a[4] ?
i know its something with dynamic memory things. iam new to this.



There''s a thread on this elsewhere on this very forum I believe. Have a look around for it.

Share this post


Link to post
Share on other sites

  • Advertisement