Archived

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

LessThanJoe

Wrote a class...got some errors...help

Recommended Posts

Ok, I've never written any classes, nor have I ever had training for them, so what I'm writing here is obviously wrong...but i'm getting an error "c:\c++\tetris\tetris.h(2) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit" here is tetris.h, if you need the .cpp I can post it here, but there's a lot of it. (btw, I will go through and rename my viariables with the proper _):
  
#include <apvector.h> 

#include "tetris.cpp" 


class TETRIS
{
	public:
		// Functions

		void newshape();
		void rotate();
	
		// accessors

		apvector lefts();
		apvector rights();
		apvector bottems();
	private:
		apvector _theshape(4, 0);
		int state = 0;
                // soon to come

                // int Boardheight = 0;

                // int boardwidth = 0;


};
  
Thanks [edit: added source tags] Edited by - Magmai Kai Holmlor on January 2, 2002 8:20:40 PM

Share this post


Link to post
Share on other sites
First, never #include a source file in a header file, it works the other way around. You make your definitions in the header and include the header in the source.

Second you should use safe include syntax to make sure that the header file is only included once. Here is the safe include syntax:

        
#ifndef MYHEADER_H //substitute your header file name here

#define MYHEADER_H //this name can technically be anything


//but it is common practise to use the

//header file name

.
.//your definitions go here

.
#endif //#endif for #ifndef MYHEADER_H



What that error is telling you is that you recursively included a file and it just kept loading it and loading it, until it ran out of space.

---
Make it work.
Make it fast.

Edited by - CaptainJester on January 2, 2002 3:16:43 PM

Share this post


Link to post
Share on other sites
Fatal Error C1076

compiler limit : internal heap limit reached; use /Zm to specify a higher limit

The compiler ran out of storage for items that it stores in its heap. Usually this is the result of having too many symbols.

One of the following may be a solution:

-Use the /Zm compiler option to set the compiler''s memory allocation limit.

-Simplify the program:
Eliminate unnecessary include files, especially unneeded #defines and function prototypes.

-Eliminate some global variables. For instance, use a pointer to allocate memory dynamically, at run time, instead of declaring a large array.

-Eliminate unused declarations.

-Break up very large functions into smaller ones.

-Break up very large classes into smaller ones.

-Split the current file into two or more files and compile them separately.


Note If you get this error message immediately upon starting the build process, you have probably specified too high a value for /Zm, given the specific details of your program. Change the /Zm value to a lower one and re-run the build.

Share this post


Link to post
Share on other sites

Most likely you have

#include "Tetris.h" in your Tetris.cpp file

AND

#include "Tetris.cpp" in your Tetris.h file

and the compiler is going into a #include infinite loop adding each file over and over and over again..

get rid of the #include "Tetris.cpp" in you .h file and compile it again.

-

Share this post


Link to post
Share on other sites
quote:

int state = 0;



You can''t do this (really). You should make a contructor and initialize it there.

  
TETRIS::TETRIS()
{
state = 0;
}


or

  
TETRIS::TETRIS() : state( 0 )
{

}

Share this post


Link to post
Share on other sites
Well, I got rid of that error, but in it's place there are now 102 others (don't you hate when that happens?)

I've looked through about the first 50 then realized all of these are probably caused by my ingorence of classes. So I was wondering if anyone could point me to a good how-to that doesn't assume I'm an idiot.

Also, if you want to look at the class so far:

www.geocities.com/azriel182/tetris.zip

I am going to go through and add all the good stuff like comments. Also, all of those random numbers will be replaced with Boardheight and Boardwidth, but they currently assume the board is 13 spaces wide with 1 row on each side for the walls (the option of weather or not to have spaces for walls will be up for grabs with this class, but I just prefer to have them for the way I'm doing the proper rotation.)


Last thing before I go, apvector is really good (and you'll need it if your checking this is), you can find the .h and the .cpp at www.collegeboard.com > site search

Edited by - lessthanjoe on January 2, 2002 6:23:41 PM

Share this post


Link to post
Share on other sites
the include statement is like this, #include , or #include "custom path", so u can go like this incase u didnt know, #include "c:\mefiles\lib\asad.h".
you only include a file to make its definitions visible in the current scope.
you dont include a .cpp file in a header because the header has no need for it... the .cpp, however, needs the header include so it can spot all the header's definitions.
...
ur tetris is a tad overhaul - > read : trig: point rotation.
i wrote a tetris once and it looked somewhat like this:
note that this is gappy code used just to demonstrate some oop.


      
void main()
{
CTETRIS Tetris(wid,hgt);
while (Tetris.Play())
;
}//main


bool CTETRIS::Play()
{
if(!GetInput()) //getinput = false if escape was hit

return false;
else
{
if(!Shape.Act())
{ //shape has collided, check to see need to remove lines

CheckLines();
//reinitialize shape

Shape.New();
}
UpdateScreen();//draw stuffs

return true;
}
}//Play


bool CSHAPE::Act()
{
Move(GetInput());//move if arrow key (left,right,etc)

Rotate(Left); //force rotate

Move(Down); //force down

if(Dead()) return false; //has collided

return true;
}//Act



you can assume that all functions have a class member scope. this is what classes are all about!


Edited by - evilcrap on January 2, 2002 7:55:16 PM

Share this post


Link to post
Share on other sites
quote:
Original post by Midnight Coder
Fatal Error C1076

compiler limit : internal heap limit reached; use /Zm to specify a higher limit

The compiler ran out of storage for items that it stores in its heap. Usually this is the result of having too many symbols.

One of the following may be a solution:

-Use the /Zm compiler option to set the compiler''s memory allocation limit.

-Simplify the program:
Eliminate unnecessary include files, especially unneeded #defines and function prototypes.

-Eliminate some global variables. For instance, use a pointer to allocate memory dynamically, at run time, instead of declaring a large array.

-Eliminate unused declarations.

-Break up very large functions into smaller ones.

-Break up very large classes into smaller ones.

-Split the current file into two or more files and compile them separately.


Note If you get this error message immediately upon starting the build process, you have probably specified too high a value for /Zm, given the specific details of your program. Change the /Zm value to a lower one and re-run the build.




Check the source code, as it was already pointed out, it''s a recursive include problem( in that particular case that is. )



"And that''s the bottom line cause I said so!"

Cyberdrek

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash

Share this post


Link to post
Share on other sites
Well, after a long time, I think I ended up at the point where I should ask this question:

Sevel .cpp files? Looks nice, but how does it work??? Doesn''t that give trouble with compiling?

Look, I now it sounds silly, but I''ve only used a single .cpp, and several header files... Worked fine for me

-Maarten Leeuwrik
"Some people when faced with the end of a journey simply decide to begin anew I guess."

Share this post


Link to post
Share on other sites
Hehe, for your future class data members, you might want to keep them case sensitive.

// int Boardheight = 0;
// int boardwidth = 0;

That''s gonna screw you up so bad in your future programming efforts if you have height with a capital Board and width with a lowercase board.

Share this post


Link to post
Share on other sites
yeah, I typed those last comments in off the top of my head. If you download the files you should see I corrected that.


EvilCrap, telling someone the first program he is writing is bad then telling him another, more complex, way to do it is probably not a good idea. Also, I know very well how to use classes once they are written, I just don't know the proper syntex for writing them.

btw, where can I find "trig: point rotation"

2nd edit:
I never did find that artice you told me about, but I think I know what you mean. Is that something where you set a center point in the shape then rotate all the other points 90 degrees around that one point (the point you select does not necessarly need to be on the shape...I didn't make that very clear)










Edited by - lessthanjoe on January 2, 2002 10:49:27 PM

Share this post


Link to post
Share on other sites
lol, after you finish your tetris, come and look at what i posted, then decide whats more complex.

rotation of point (x,y):
single t = theta;
newx = oldx * cos(t) - oldy * sin(t);
newy = oldx * sin(t) + oldy * cos(t);

just make sure that theta is the right units for the trig funcs.
i think thats the formula.

if you plan to program games and stuff, get a reference book on applied calc and trig/geometry. i happended to have lost mine for the moment =).

there have got to be at least 2 million posts on rotation at gamedev =).

Edited by - evilcrap on January 2, 2002 10:38:53 PM

Share this post


Link to post
Share on other sites
and nowhere did i say your program was bad.
i just wanted to show you a more oo way of it.
YOU DID SAY U HAD NEVER USED CLASSES B4...
sorry if i mislead u to my bizare ways.
if you think thats complex then youve got alot comming to you.

Edited by - evilcrap on January 2, 2002 11:24:39 PM

Share this post


Link to post
Share on other sites
Any idea how I can get the x and y of a point when I'm using a (ap)vector?

Edit:
nevermind, I'll just do a 2d array (aka (ap) matrix)

Edited by - lessthanjoe on January 2, 2002 11:24:12 PM

Share this post


Link to post
Share on other sites
i have never worked with an (ap)vector
but if it had 2d vector parts then u coiuld use polar rotation:
newx = radius * cos(theta) + basex
newy = radius * sin(theta) + basey

Share this post


Link to post
Share on other sites
Well, even though you said nevermind I thought I would answer the previous post for you.

If I understand what you are asking (I''ve never heard of an apvector (it is a user-defined type?), then this is how you can find the (x,y).

You know that a vector essentially represents direction and magnitude (in other words, it''s not scalar). To find the x-coord position you just use some trigonometry.

/|
/ |
v / | I know the drawing is bad, but you''ll get the idea.
/ |y To find the x-coord just find the length (magnitude)
/ | of the vector in the x direction with this:
/_t___| x = cos(t)*v For y-coord: y = sin(t)*v


That''s just 2-dimensional, but 3d is fairly easy since anything 3d can be broken down in 2d components.

Hopefully that helped introduce you to some basic trigonometry.

Share this post


Link to post
Share on other sites
a direction is a scaler (just figured I''d point that out to show I DO understand math.)

apvectors (and apstring + apmatrix) are all user defined classes made for an ap high school (freshman college level) corse. They serously do kick some. You can find all of those (I suggest apstring...so much easier for the newbies to learn with) at www.collegeboard.com, click on site search, then do a search for those.

apvector is pretty much a poorly named array that is much easier to work with then reguler arrays (there are functions that let you resize it and return the length, plus passing them into and from functions is so easy with it (which I''m sure is easy for people of your skill))

and the reason I was hoping someone could point me stright to a good guide is because I have ALWAYS had bad luck when searching for guides on the internet. Thanks for that though...to repay your effort I''ll be sure to spend a little bit of my time looking through that for one...
Eye for an eye

Share this post


Link to post
Share on other sites
I spent quite a while searching for a good guide, but didn''t find any.

So I spent some time looking over other header files/classes/ect, and the only possible thing for those 102 errors that I can think of is that the compiler doesn''t know what apvector is.

Anyone have any ideas on how I can make it learn what apvector is? (kicking and yelling at it don''t seem to work very well...but further testing is guarneteed to happen)

Share this post


Link to post
Share on other sites
C''mon, we are rotating by 90 degrees man! Just flip some X and Y values, and change some signs, and you are finished

-Maarten Leeuwrik
"Some people when faced with the end of a journey simply decide to begin anew I guess."

Share this post


Link to post
Share on other sites
umm...This post had nothing to do with rotation, evilcrap was just showing me a better way to do rotation then what I did.

if you want to yell at me for not knowing classes...go for it.

Share this post


Link to post
Share on other sites
the only reason it wouldnt know what apvector is is if it wasnt defined anywhere -
have you defined the headers containing apvector?
do those headers actually contain apvector?
is the include code reachable?

does the compiler specifically say that apvector is undefined or not recognized as a valid identifier?

Share this post


Link to post
Share on other sites