The Partridge Family were neither partridges nor a family. Discuss.
-
Radical
- Posts: 38
- Joined: January 15th, 2017, 9:16 pm
- Location: Ontario
Post
by Radical » October 5th, 2017, 8:10 pm
"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: Select all
#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)
-
Yumtard
- Posts: 575
- Joined: January 19th, 2017, 10:28 pm
- Location: Idiot from northern Europe
Post
by Yumtard » October 5th, 2017, 8:15 pm
PutPixel isn't a static function, so you need to call it on an instance of the class. Use the gfx object.
gfx.PutPixel()
-
Radical
- Posts: 38
- Joined: January 15th, 2017, 9:16 pm
- Location: Ontario
Post
by Radical » October 5th, 2017, 8:17 pm
But then identifier gfx is undefined. Hold on, I will mess around and see if there's something I can do.
-
Yumtard
- Posts: 575
- Joined: January 19th, 2017, 10:28 pm
- Location: Idiot from northern Europe
Post
by Yumtard » October 5th, 2017, 8:18 pm
gfx is created in game.cpp You can pass a reference to it
void Platform::DrawPlatform(int whatever, Graphics& gfx)
-
Radical
- Posts: 38
- Joined: January 15th, 2017, 9:16 pm
- Location: Ontario
Post
by Radical » October 5th, 2017, 8:39 pm
Code: Select all
void Platform::DrawPlatform(int &x, int y, int w, int r, int g, int b, Graphics& gfx)
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.
-
Yumtard
- Posts: 575
- Joined: January 19th, 2017, 10:28 pm
- Location: Idiot from northern Europe
Post
by Yumtard » October 5th, 2017, 8:47 pm
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
Last edited by
Yumtard on October 5th, 2017, 9:08 pm, edited 1 time in total.
-
Radical
- Posts: 38
- Joined: January 15th, 2017, 9:16 pm
- Location: Ontario
Post
by Radical » October 5th, 2017, 9:03 pm
Ah, thank you! That did the trick.
-
chili
- Site Admin
- Posts: 3948
- Joined: December 31st, 2011, 4:53 pm
- Location: Japan
-
Contact:
Post
by chili » October 6th, 2017, 3:16 am
Yumtard is on fire with the troubleshooting help. Much appreciated bro
Chili
-
albinopapa
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Post
by albinopapa » October 6th, 2017, 8:56 am
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
-
Yumtard
- Posts: 575
- Joined: January 19th, 2017, 10:28 pm
- Location: Idiot from northern Europe
Post
by Yumtard » October 6th, 2017, 11:00 am
@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