[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I have some c++ code for a platformer game. I'm trying to

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 5
Thread images: 1

File: cpp.png (62KB, 1385x1557px) Image search: [Google]
cpp.png
62KB, 1385x1557px
I have some c++ code for a platformer game. I'm trying to make the constructor for a platform object which can have different materials. I've decided to store these materials as enums but when trying to make the enum an argument in the constructor i have some problems.

in Platform.h
[code]
#include "vect2d.h"
#include "Object2D.h"
#pragma once

class Platform : public Object2D
{

private:

public:
enum material { DIRT, SNOW, ICE, ROCK, WOOD };

Platform(vect2d c, int heal, float vY, float vX, float l, float h, material m);

};
[code]
#include "Platform.h"
#include <math.h>
#include "GL\freeglut.h"

Platform::Platform(vect2d c, int heal, float vY, float vX, float l, float h, material m) : Object2D(c, heal, vY, vX, l, h)
{
this->material = m;
}

[/code]

the problem is that i get the error "type name is not allowed" when trying to set this->material in the constructor.
>>
>>276950
>some problems
elaborate, give the compiler output

also:
pragma once should be at the top and public member variables are a bad idea.
>>
>>276950
I think the default type for an enum is int. I'm pretty sure you should have the enum in some scope accessible to wherever the class is instantiated, and pass an int into the constructor, using the name of something in the enum.

so

[code]
enum Materials
{
MAT_DIRT,
MAT_SNOW,
MAT_ICE,
MAT_ROCK,
MAT_WOOD
}

class Something
{
public:
Something(int material);

private:
int material;
};

int main()
{
Something something(MAT_WOOD);
return 0;
}
[/code]
>>
>>277806
as for where you should put the enum, I have no fucking idea. maybe have an 'enums.h' file or something but that could be shit idk.
>>
material is a type. So when you say "material = 1" it's like saying "int = 1", which hopefully even a moron like you knows is wrong. You need to add a class member of type material, like "material mat", and then you should be saying "this->mat = m".
Thread posts: 5
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.