C++ :: Using Enum Defined In Class
Apr 1, 2013
I am trying to write a game in C++ with SDL, and I have a class that allows me to handle events. The class is actually really simple: It takes the SDL_Event, then 2 variables from 2 different enum to determine for which Event and which Key should be checked, and then a variable that will be modified if the event happens. Here is the class
EventParser.h
#include "SDL.h"
#include "SDL_opengl.h"
template<class T>
[Code]...
As of yet the variable only changes if the Left key has been released, it will be extended if the error has been solved.
Then, in my main.cpp file I define the Event and the EventParser as
SDL_Event event;
EventParser<float> ep;
And in a loop, the parseEvent function is called like this:
ep.parseEvent(event, ep.KeyUp, ep.LEFT, &xVariable);
However I get a linker error (not the first one I got when programming this game)
error LNK2019: unresolved external symbol "public: void __thiscall EventParser<float>::parseEvent(union SDL_Event,enum EventParser<float>::EventType,enum EventParser<float>::KbdKey,float *)" (?parseEvent@?$EventParser@M@@QAEXTSDL_Event@@W4EventType@1@W4KbdKey@1@PAM@Z) referenced in function _SDL_mainC:UsersPrideRageDocumentsVisual Studio 2012ProjectsSDL_TestSDL_Testmain.objSDL_Template
View 6 Replies
ADVERTISEMENT
Apr 23, 2013
I cannot wrap my head as to how to access my enum class Azimuth.
Code: #ifndef BOUSOLE_H
#define BOUSOLE_H
#include <iostream>
#include <string>
#include "StringHandler.h"
class Bousole{
[code]...
And here is where I am trying to access my enum for testing/understanding purposes
Code: #include "Bousole.h"
using namespace std;
int main (int argc, char *argv[]){
cout <<"Start bousole" << endl;
Bousole b;
[Code] ....
View 6 Replies
View Related
May 29, 2013
I really confused with constructor (default constructor and constructor with parameters)
I coded this problem
and I worked almost, but I stock in constructor
Code:
class Tier {
public:
enum TIER_MAKE
[Code] ....
This is tier class and I have to finish constructor in class car (for simple, I skip detail code) -red things are the parts from class Tier
Code: Car()
: make(NULL), passengers(0), fuelcap(0.0), efficiency(0.0), tier(Tier::nexen)
{ }
[Code] ....
And someone said default constructor part has to be this
Code:
car( Tier::TIER_MAKE p_tiermaker = Tier::nexen )
//after i skip
but default constructor should be no parameter...? isn't it?
View 1 Replies
View Related
Jan 4, 2014
I had defined enums in a class like this:
Code:
class Enums {
public:
enum COLOURS {BLACK, GRAY, RED, ORANGE, YELLOW,
GREEN, BLUE, PURPLE, BROWN, PINK, WHITE};
}
But I don't want to use the enums inside of that class. I want to use it in the main file like this:
Code:
#include <iostream>
using namespace std;
void SetColor(const int COLOR) {
cout << COLOR << endl;
}
int main(int argc, char* argv[]) {
void SetColor(BLACK);
return 0;
}
Without getting a syntax error.
View 3 Replies
View Related
Jan 2, 2015
I made this code (it does nothing I am just learning about classes, I was learning about friend functions) and I don't understand what is wrong, here is the code:
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
class MyClass {
public:
friend int add(int a, int B)/>;
[Code] ....
I know i didn't need to include cstdlib and cstring for this code but as I said, it's not supposed to be something it's just for practice and I was working on char arrays. My question is about the part where i try to define the function:
int MyClass::add(int a, int B)/>
{}
My compiler(Microsoft Visual C++ 2010 Express) says that class MyClass has no member "add" even though it does...
View 3 Replies
View Related
May 21, 2014
I have been working a project in C++. I have TTTMain.cpp file that has all the function calls, TTTFuntions.cpp that has all the functions, I have TTT.h file that has all the prototypes and variables and additionally I have Winner.h that has enum class Winner declaration in it. Here is my block of codes:
Winner.h file:
#ifndef winner
#define winner
enum class Winner {
[Code]....
My question is when I compile this gives me error on
Winner gameSquares[] = { Empty, Empty,Empty, Empty, Empty, Empty, Empty, Empty, Empty };
with saying "invalid use of non-static data data member" and It says "Empty was not declared in this scope."
I know calling enum is very very trick.
View 3 Replies
View Related
Apr 6, 2014
I got an array class, but I'm getting this error:
Error1error C2953: 'Array2D' : class template has already been defined
Here's the code:
#include "Tools.h"
template <typename T>
class Array2D {
T** arr;
int xSize;
int ySize;
[Code] .....
View 3 Replies
View Related
Jul 25, 2012
Let's take a look at the code first,
Code:
class B
{
public:
int data;
};
class D : public B
{
public:
int data;
};
Both B and D defines data. I wonder if there is any difference between them?
View 2 Replies
View Related
Aug 26, 2013
Assume this class:
class GenericTrafficLight {
public:
virtual enum LightState;
void setLightState(LightState newState) {
currentState = newState;
}
private:
LightState currentState;
};
And this deriving class:
class FuturisticTrafficLight : public GenericTrafficLight {
public:
enum LightState {
LIGHT_STATE_RED = 0,
LIGHT_STATE_YELLOW = 1,
LIGHT_STATE_CYAN = 2,
LIGHT_STATE_GREEN = 3
};
};
This yields this error: "C2911 (...) cannot be declared or defined in the current scope" in the deriving class's enum definition.
View 5 Replies
View Related
Nov 29, 2014
I am working on a program that uses a class I created called Student. I want to be able to add different students to a Binary Search Tree, and use the student's gpa (grade point average) to compare students with each other and place them in the correct location in the Tree.
Student class:
#ifndef STUDENT_H
#define STUDENT_H
#include <string>
#include <iostream>
#include <iomanip>
class Student{
friend ostream& operator<<(ostream& out, const Student& stu);
[Code] ......
View 3 Replies
View Related
Mar 15, 2013
I am a beginner with C++, taking a class right now. The lab this week is to create a user defined class and have it accesses in a separate .h header file from the main.
I think I'm finding my way through it, but I'm getting a complie error that makes no sense to me:
1> Resistor.cpp
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2
esistor.h(11): error C2146: syntax error : missing ';' before identifier 'resistor'
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2
[Code] .....
Here is the first portion of the .h file:
#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <math.h>
#include <string>
class CResistor{
double res1, res2, res3, percentage, Nominal, Tolerance;
[Code] ....
View 16 Replies
View Related
Apr 12, 2014
I am working on an assignment in which i have to perform th following task
myClass itsObject1,itsObject2;
itsObject2=5000+itsObject1;
I have defined overloaded operator as follows in the header file but in the cpp file of the class it gives error.
friend vli &vli::operator + (int &a,vli &obj);
How to define it in cpp file of my class?
View 1 Replies
View Related
Aug 19, 2014
I am attempting to implement function pointers and I am having a bit of a problem.
See the code example below; what I want to be able to do is call a function pointer from another pointer.
I'll admit that I may not be explaining this 100% correct but I am trying to implement the code inside the main function below.
class MainObject;
class SecondaryObject;
class SecondaryObject {
public:
[Code]....
View 10 Replies
View Related
Jan 19, 2014
I'm trying to make a simple C++ program in which the user must try to guess a number, if they guess too high it says "too high" and if they guess too low it says "too low".
I also decided to add a feature which allows them to select how many tries they would like to guess the number. I tried to make "tries" type an enum so if the user could not pick an invalid number but for some reason i cannot use it in an if statement.
here is the code and i am getting the first error on line 27:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int guess;
[Code]....
View 7 Replies
View Related
Sep 30, 2014
I have an enum like:
Code:
typedef enum mac_type_e{
STATIC_MAC,
BLACKLIST_MAC
} mac_type_t; and I want to use this type in a structure that's declared like:
Code:
typedef struct lan_mac_s {
UINT16 lanmacid;
enum mac_type_t lan_mac_type_pp;// user mac type per port, 20 mac_type_t array, 0 = static, 1 = blacklisted now,
The compiler tells me:
Code:
incomplete type is not allowed
enum mac_type_t lan_mac_type_pp;// user mac type per port, 20 mac_type_t array, 0 = static, 1 = blacklisted
But if I remove the preceeding "enum" keyword, it compiles fine.
View 2 Replies
View Related
Feb 3, 2014
I defined
enum symbol {A, B, C};
in file A.h
and in file B.h, I #include "A.h" , but still get error of A , B and C unresolved when using them. WHy?
View 15 Replies
View Related
Jul 4, 2014
I'm trying to convert the enum type {PG, R, G, PG-13, etc.} to strings so i can use it in cout statement but no matter what i put inside switch(), the compiler keeps saying Error: expression must have integral or enum type. What am I doing wrong exactly?
Movie covert_rating(Movie r) {
switch (r) {
case PG:
return "PG";
break;
case R:
return "R";
[code]....
View 4 Replies
View Related
Jan 25, 2015
I want to convert an enum to a text string.
enum BREED {YORKIE,CAIRN,DANDIE,SHETLAND,DOBERMAN,LAB};
View 4 Replies
View Related
Jul 25, 2012
I am learning OOP Console Programming and i got some error in my code;
Here is my code
#include <iostream>
using namespace std;
enum ch {CD,DVD}
class disk {
private :
ch choice;
[Code] ....
I want to compare the enum variable to char c, and cout CD when user press 'c' and cout DVD when user press 'd'. I got error like this :
error : expected ')' before 'c' at first line after public
Note : I must use enum to store value.
View 7 Replies
View Related
Apr 2, 2012
Any way to use a string to access a specific item in a matrix of int[X].
I have a program which uses enums as iterators to reference a large amount of data. To select an item in the matrix, the user will enter a string, which is also an enum, which also must serve as an iterator for something in the matrix. Here is a toybox example:
#include <iostream>
#include <string>
using namespace std;
enum NyNumbers { First, Second, Third, Forth, LAST_VALUE };
int main(int argc, char* argv[]) {
int Matrix[LAST_VALUE] = { 1, 3, 7, 12 };
[Code] .....
The idea is the user executes the program by typing "./RUN First" to print out the first element in the MyNumbers array, "./RUN Second" to access the second, and so on. I can't use static numbers for the iterator. (i.e., "./RUN 1") I must reference by enum/string.
When run, the output of this problem is thus:
====================================================================
user@debian$ ./RUN Second
Matrix[ atoi(Second) ]: 1
user@debian$
====================================================================
BTW, if I change line 12 to this
====================================================================
cout<<Matrix[ argv[1] ]<<"
";
====================================================================
The error message is this
====================================================================
user@debian$ make
g++ -g -Wall -ansi -pg -D_DEBUG_ Main.cpp -o exe
Main.cpp: In function `int main(int, char**)':
Main.cpp:12: error: invalid types `int[4][char*]' for array subscript
make: *** [exe] Error 1
user@debian$
====================================================================
Which isn't unexpected. How to input the enum as argv[1]?
View 2 Replies
View Related
Aug 31, 2013
As we know in C there is no checking if values passed to a function that takes enum are correct, that is if they have been defined in this enum. Example from Enums in C | Occasionally sane ([code] tags don't work on my fx 18.0.1 this is why I put in on pb): [URL] ......
Here c - How to check if an enum variable is valid? - Stack Overflow they say that common convention is add check whether value passed as the parameter is not bigger than the maximum value in enum. But how about situations when enum is composed of numbers from 1-20 and then from 500-510?
View 4 Replies
View Related
Dec 2, 2013
I defined
enum boundaryType_t {inside, inlet, outlet, wall, periodic};
now I have file written like this:
inside outlet
I want my program read the file and when encounter any enum type, instead of treating it as a string, I want the program store it in memory as a enum value.
How can I do that?
string s;
ifs>>s;
s // how to convert it to enum???
View 5 Replies
View Related
Feb 25, 2014
It is working:
#include <iostream>
#include <string>
#include <vector>
#include <map>
const int ENUM_NOT_FOUND = -1; const std::string NEW = " ";
enum Day {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
[code]....
Ouput with GCC 4.8.1:
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Name a day: Friday
day = Friday
But the problem is that whenever I define a new enum, I have to define the << and >> overloads for the new enum again. Isn't there a way to template that as well, so that the << and >> overload needs to be defined just once? My atttempt:
template<typename Enum>
std::ostream& operator << (std::ostream& os, Enum en) {
return os << EnumConversions<Enum>::toString (en);
[Code] .....
fails to compile. I guess the problem is Enum is not known at compile time, even though it should be deducible during run time? Error mentions ambiguous overload for operator>>.
View 6 Replies
View Related
Oct 13, 2014
I need to do this simple Battleship game project for my C++ class. Here is my current code so far:
#include <iostream>
#include <array>
#include <string>
using namespace std;
enum BShip{ EMPTY, BTLSHIP, HIT, MISS };
const int BSIZE = 6;
const int BTLSHIP_SIZE = 4;
class Battleship {
private:
array<array<Bship, BSIZE>, BSIZE> sea, hits;
[code]....
For some reason, I'm getting errors on the string and enum declarations.
View 10 Replies
View Related
May 7, 2013
Is there a quick way to determine if a value is in an enum? Consider for example,
public enum GenderEnum
{
Unknown = 0,
[Code].....
I don't want to convert to an array if possible, just check the enum and get a yes/no answer.
View 1 Replies
View Related
Sep 6, 2014
So far I have the following code:
// Purpose: To write a program that displays the number of millimeters higher the current level the ocean level will be in
// in 5, 7, and 10 years.
# include <iostream>
# include <string>
using namespace std;
int main() {
float X = 10;
string Y="";
[Code] ....
But I get the following error message:
IntelliSense: expession must have integral or unscoped enum type
three times in a row for lines 25, 27, and 29 and I don't understand or know why?
In case the purpose does make sense here are the directions:
2.7: Ocean Levels
Assuming the ocean’s level is currently rising at about 1.5 millimeters per year, write a program that displays
•The number of millimeters higher than the current level that the ocean’s level will be in 5 years,
•The number of millimeters higher than the current level that the ocean’s level will be in 7 years,
•The number of millimeters higher than the current level that the ocean’s level will be in 10 years,
Output labels:
Each value should be on a line by itself, preceded by the a label of the form:
In X years the ocean's level will be higher by Y millimeters.
where X is the number of years (5, 7 or 10) and Y is the value you calculate.
View 16 Replies
View Related