Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Tutorial 9: Classes help
 Post Posted: October 5th, 2017, 8:10 pm 
User avatar

Joined: January 15th, 2017, 9:16 pm
Posts: 22
Location: Ontario
"a nonstatic member reference must be relative to a specific object."

This is the error message I get when I try to run the following code:
Code:
#include "Platform.h"
#include "Graphics.h"

void Platform::DrawPlatform(int whatever)
{
   Graphics::PutPixel(whatever);
}

It seems I can not include PutPixel in my Platform.cpp file. I tried the same with other variables I created in Game.h and the same error popped up. (After making them public of course)


Top 
 Profile  
Reply with quote  
 Post Posted: October 5th, 2017, 8:15 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
PutPixel isn't a static function, so you need to call it on an instance of the class. Use the gfx object.

gfx.PutPixel()

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: October 5th, 2017, 8:17 pm 
User avatar

Joined: January 15th, 2017, 9:16 pm
Posts: 22
Location: Ontario
But then identifier gfx is undefined. Hold on, I will mess around and see if there's something I can do.


Top 
 Profile  
Reply with quote  
 Post Posted: October 5th, 2017, 8:18 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
gfx is created in game.cpp You can pass a reference to it

void Platform::DrawPlatform(int whatever, Graphics& gfx)

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: October 5th, 2017, 8:39 pm 
User avatar

Joined: January 15th, 2017, 9:16 pm
Posts: 22
Location: Ontario
Code:
void Platform::DrawPlatform(int &x, int y, int w, int r, int g, int b, Graphics& gfx)

Quote:
1>Platform.cpp
1>d:\libraries\documents\chili framework\platformer\engine\Platform.h(6): error C2061: syntax error: identifier 'Graphics'
1>Platform.cpp(7): error C2511: 'void Platform::DrawPlatform(int &,int,int,int,int,int,Graphics &)': overloaded member function not found in 'Platform'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have the same code in the header file, so I'm not sure what it's talking about. Thanks for continuing to help troubleshoot.


Top 
 Profile  
Reply with quote  
 Post Posted: October 5th, 2017, 8:47 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
It looks like you're including "Graphics.h" inside the cpp file.

Instead, you need to include it in the h file. Otherwise, the compiler wont know what you're talking about when you declare your function that takes a reference to a graphics object. Remember the cpp file is including the h file, not the other way around :)

So yeah, just move #include "Graphics.h" from the cp file to the h file

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Last edited by Yumtard on October 5th, 2017, 9:08 pm, edited 1 time in total.

Top 
 Profile  
Reply with quote  
 Post Posted: October 5th, 2017, 9:03 pm 
User avatar

Joined: January 15th, 2017, 9:16 pm
Posts: 22
Location: Ontario
Ah, thank you! That did the trick. :)


Top 
 Profile  
Reply with quote  
 Post Posted: October 6th, 2017, 3:16 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Yumtard is on fire with the troubleshooting help. Much appreciated bro :)

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: October 6th, 2017, 8:56 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2782
Location: Oklahoma, United States
He'll be able to take over my role soon.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: October 6th, 2017, 11:00 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
@Chili np! Seems like a good way to improve/get some extra practice.

albinopapa wrote:
He'll be able to take over my role soon.


haha, I'll never be able to do that

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 10 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: