Hmmm, small problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Hmmm, small problem

Post by Endar »

Okay, I have this code:

Code: Select all

int main( void ){
     HillTerrain terrain(); // you can also specify terrain params here
     terrain.Generate();

     for( int x = 0; x < terrain.GetSize(); ++x ){
          for( int y = 0; y < terrain.GetSize(); ++y ){
               float z = terrain.GetCell( x, y );
               // do whatever with the z values here to draw your terrain
          }
     }
return 0;
}
And when I try to compile it, I get the errors that left of ".Generate", ".GetSize" and ".Cell" must have class/struct/union type.

I understand the error, but I'm confused as to why I'm getting it. "HillTerrain" is a class and terrain is a declared variable otherwise, I'd be getting "terrain is undeclared identifier", which I'm not.

Ideas??
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Is terrain a class or a pointer to a class? Try "terrain->Generate()" Instead.

And by the way I love the cookie monster pic!
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

I've tried and it just gives the same 4 errors!!

:evil:
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
VPB
Posts: 36
Joined: Sat Apr 10, 2004 8:02 am

Post by VPB »

If HillTerrain is another class in another file, you need to create a header file and include that file with your current class
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

The class HillTerrain is a class defined in the header file, and the functions are defined in a cpp file. There is also another file that contains the inline functions.

??????

Well, anywayz, the code in the 3 other files aren't mine, and they've been put up for download on a site a while ago, so I think that i can assume that they work. And the code I posted above was just cut and paste exactly how he said to use it.

http://www.robot-frog.com/3d/hills/code.html
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

First, did you properly included HillTerrain.h ?
Second, did you used appropriate namespace - RobotFrog ?
Tomasz Nowakowski
Openoko - www.openoko.pl
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Yep, I'm using the namespace and I've included the header file.

Strange, but if you look in the header file and the inl file nowhere is the cpp file included. But it doesn't matter, I'm still getting the same 4 errors.

This is the whole of the file I'm trying to compile:

Code: Select all

#include "rfHillTerrain.h"

using namespace RobotFrog; // the class is in this namespace

int main( void )
{
	HillTerrain terrain(); // you can also specify terrain params here
    terrain.Generate();
        
    for( int x = 0; x < terrain.GetSize(); ++x )
    {
        for( int y = 0; y < terrain.GetSize(); ++y )
        {
            float z = terrain.GetCell( x, y );
            // do whatever with the z values here to draw your terrain
        }
    }
return 0;
}
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Acki

Post by Acki »

hmmm...
maybe you have to declare your terrain like this:

rfHillTerrain terrain();

or maybe without braces ???
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

You can't declare as 'rfHillTerrain' because the class name is 'HillTerrain' and you would get an error, and without the braces only works if there aren't any parameters to be passed to the contructor, and this has many to be passed, even though they are setup as default and you don't have to pass any unless you want to change them.
Thanx anyway Acki :D
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

I think you want HillTerrain terrain instead of HillTerrain terrain(). If you are nto passign a constructor any arguements do not use parentheses. When you say HillTerrain terrain() your compiler thinks you are declaring a function accepting no arguments and returning a HillTerrain.
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Okay, well I've declared it as "HillTerrain terrain;" and I get 3 errors. They are all linking errors saying that it can't find the constructor, desctructor and the function "Generate".

So, I figure, okay, I don't think that the actual cpp file has been included in any of the files, so I include that and it gives me 29 errors, 7 warnings.

The first one is: " 'HillTerrain' : 'class' type redefenition"
The next 18 consist of "HillTerrain::<function name>() already has a body"

Then the 7 warnings: "possible loss of data, conversion to int from float"

Then the rest of the errors: " '<function name>' : error in function definition or declaration; function not called "

For the last set of errors, it looked like it was going through the cpp file that I downloaded as well as my own and was just giving that error for each call to a function.

EDIT: I do think that you were right about declaring without the braces. - Apologies Acki :D But I still have the above problem. Computers!!!! <sigh>
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Endar wrote:You can't declare as 'rfHillTerrain' because the class name is 'HillTerrain'
Hmmm....
well, I'm not that familiar with c++, but if the class name is "HillTerrain" do you not have to include a "HillTerrain.h" instead of "rfHillTerrain.h" ???
I always thought that the header file is always named like the class name... :?
Well, I also could be wrong... :shock:
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

@Acki:
Yes, you are wrong. Class name has nothing with header file name. Mostly becouse you can have headers without class or with more then one ;)
Tomasz Nowakowski
Openoko - www.openoko.pl
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

I think the errors:
The first one is: " 'HillTerrain' : 'class' type redefenition"
The next 18 consist of "HillTerrain::<function name>() already has a body"
are because you already have the file included and you have included it again(ie the class has been redefined).

Does the HillTerrain class have a default constructer for when no arguments are included? I think that it does not and it requires arguments at the time of declaration.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Btw, in Java the filename must always be named like the main class that it contains.
Post Reply