Jump to content
  • Advertisement

Archived

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

pauljg

Classes not working as they should

This topic is 5937 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''m battling away at a 3ds object loader, I''ve got a crude routine working - but I thought I''d try and use classes, since it would help when define multiple objects. I''ve got a routine called ''loadasc()'' - that loads in all the object data. Now if I call the routine from WINMAIN like so: loadasc() drawit(); it works fine, BUT if I try to call the same routine from within a class it doesnt work. I''m not sure whats happening.. is it not defining the class properly ? or is it just not getting to the routine ?? here''s my class code: class sprite{ private: public: sprite(void); ~sprite(); }; sprite::sprite(void) { loadasc(); } sprite::~sprite() { } Like I''ve said, if I call the loadasc routine from winmain the routine works fine, but if I stick it in a class it doesnt. What am I doing wrong ?? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Do you instantiate an object of that class? like

//...somwhere in main(), or WinMain()
sprite s;
//...

Did you even try to put a breakpoint on that function call to see whether it gets called or not?

Forever trusting who we are
And nothing else matters
- Metallica

Share this post


Link to post
Share on other sites
Yes, and Yes..

Here''s a snippet of the full code, perhaps that may give you some clue. (I''m not that experienced with classes, so I expect I''ve done something really daft anyway)

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include .......
....


void loadasc(void);

struct {
int num_of_v;
int num_of_f;
float vertx[50];
float verty[50];
float vertz[50];
int face1[50];
int face2[50];
int face3[50];
int colr[50];
int colg[50];
int colb[50];
} object;

class sprite{
private:
public:
sprite();
~sprite();
};

sprite::sprite()
{
loadasc();
}

sprite::~sprite() { }

void loadasc(void)
{
FILE *fp;
int tst,tst2;
float x,y,z;

char line[80];
char trash[20];

if ((fp=fopen("how.asc","r"))==NULL) {return; }

fgets(line,80,fp); fgets(line,80,fp);
fgets(line,80,fp); fgets(line,80,fp);

sscanf(line,"Tri-mesh, Vertices: %d Faces: %d",&object.num_of_v,&object.num_of_f);
//printf("%d = %d \n",object.num_of_v, object.num_of_f);
...
...
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
sprite obj();
...

..
}

Share this post


Link to post
Share on other sites
Try (maybe) to write a method that does the same, but operates on class-members, so it''s more independent from the other things.

Share this post


Link to post
Share on other sites
quote:
Original post by pauljg
sscanf(line,"Tri-mesh, Vertices: %d Faces: %d",&object.num_of_v,&object.num_of_f);

"object" is the class name, which means you can''t have an instance of the class named "object".

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
I''m sorry but I just dont understand what your saying.

The structure ''object'' is global, so should''nt the contents be accessable from within the constructor ?.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
object is the name of a struct, you need to declare a variable of type object such as:
object object1;

then use that variable

Share this post


Link to post
Share on other sites
Yeap, done that now:

struct objec {
int num_of_v;
...
...} object;

Makes no difference though

What bugs me though is that if I call the loadasc() routine outside of the class it works fine, soon as I try inside NOTHING !.

Sorry for all the posts, this is the last time.. If it cant be sorted this time then I'll just not bother with bloody classes EVER !.

I managed to get around them for 10 years just using C, but its all starting to quickly get beyond me.

[edited by - pauljg on April 21, 2002 4:59:14 AM]

Share this post


Link to post
Share on other sites
are you sure that
  
sprite obj();

isn't being compiled as a local function definition?

//edit: damn source tags are too big

[edited by - sjelkjd on April 21, 2002 5:01:54 AM]

Share this post


Link to post
Share on other sites
That''s it !!! Thank you so much.

I guess Classes will live to fight another day. I''m just lucky you guys the other side of the globe are still up !.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!