@bamu wrote:
Hello ofForums,
Today I’m attempting to make my own custom class for a simple card game using OF.
I’ve decided to call the ofCard which will contain the position and size of each card. With that I’ve created a new header file and new c++ file for it and linked the files to ofApp.h, ofApp.cpp, and main.cpp.
However when I go to use the new object, I get an indetifier is undefined error. Could someone illuminate where I’ve gone wrong?
ofCard.h //
#ifndef ofCard_h
#define ofCard_h
#include “ofMain.h”//-------------------------------------------------
class card {public:
void set(int x, int y, int width, int height);
void print(string label);
int get();int xPos;
int yPos;
int xWidth;
int yHeight;
};#endif
ofCard.cpp //
#include “ofCard.h”
//----------------------------------------------
void card::set(int x, int y, int width, int height) {
xPos = x;
yPos = y;
xWidth = width;
yHeight = height;
}void card::print(string label) {
printf("\nofCard %s-------//", label.c_str());
printf("\n xPos:\t%d", xPos);
printf("\n yPos:\t%d", yPos);
printf("\n xWidth:\t%d", xWidth);
printf("\n xHeight:\t%d", yHeight);
}
int card::get() {
return xPos, yPos, xWidth, yHeight;
}ofApp.h //
#include “ofCard.h”
//----------------------------------------------
void card::set(int x, int y, int width, int height) {
xPos = x;
yPos = y;
xWidth = width;
yHeight = height;
}void card::print(string label) {
printf("\nofCard %s-------//", label.c_str());
printf("\n xPos:\t%d", xPos);
printf("\n yPos:\t%d", yPos);
printf("\n xWidth:\t%d", xWidth);
printf("\n xHeight:\t%d", yHeight);
}
int card::get() {
return xPos, yPos, xWidth, yHeight;
}ofApp.cpp //
#include “ofApp.h”
#include “ofCard.h”//--------------------------------------------------------------
void ofApp::setup(){
card newCard;newCard.set(500, 500, 150, 200);
newCard.print(“test card”);}
//--------------------------------------------------------------
void ofApp::update(){}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(50, 50, 50);
ofSetColor(255, 255, 255);
ofDrawRectangle(newCard.xPos, newCard.yPos, newCard.xWidth, newCard.yHeight);
}
Posts: 2
Participants: 1