Object for Custom Class: identifer is undefined error

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);
}

I’ve updated the ofCard class to use a standard constructor rather than setup, but it has the same problem. Here’s the code:

ofCard.h //

#ifndef ofCard_h
#define ofCard_h
#include “ofMain.h”

//-------------------------------------------------
class card {

public:
card(int x, int y, int width, int height);
card();

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”

//----------------------------------------------

card::card(int x, int y, int width, int height) {
xPos = x;
yPos = y;
xWidth = width;
yHeight = height;
}

card::card() {
xPos = 500;
yPos = 500;
xWidth = 150;
yHeight = 200;
};

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 // no changes

ofApp.cpp //

#include “ofApp.h”
#include “ofCard.h”

//--------------------------------------------------------------
void ofApp::setup(){
card newCard;

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);
}

Fixed:

I had to declare card newCard in ofApp.h like this…

#pragma once

#include “ofMain.h”
#include “ofCard.h”

class ofApp : public ofBaseApp{

public:
void setup();
void update();
void draw();

  card newCard;

  void keyPressed(int key);
  void keyReleased(int key);
  void mouseMoved(int x, int y );
  void mouseDragged(int x, int y, int button);
  void mousePressed(int x, int y, int button);
  void mouseReleased(int x, int y, int button);
  void mouseEntered(int x, int y);
  void mouseExited(int x, int y);
  void windowResized(int w, int h);
  void dragEvent(ofDragInfo dragInfo);
  void gotMessage(ofMessage msg);	

};