Hi. I'm having a problem getting started with C++.
The setup() method in testApp.m is called first, which initializes the application, where I create my base carousel, then attempt to add a new section to it. After this, draw() is repeatedly called, or it should be... I get an EXC_BAD_ACCESS when I try to find the size of my vector and I can't for the life of me see why. The debugger indicates that there is an objects in the vector, so why can't I access the size of it?
Sorry, maybe not enough of the code posted there, I tried to keep it brief. The execution process is handled, and first calls the setup() method of testApp.cpp, then the draw() consecutively.
Any ideas?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// main.cpp
#include "ofMain.h"
#include "testApp.h"
#include "ofAppGlutWindow.h"
//========================================================================
int main( ){
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new testApp());
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// testApp.h
#pragma once
#include "ofMain.h"
#include "oscReceiver.h"
#include "ofxUI.h"
#include "carousel.h"
class testApp : public ofBaseApp{
public:
void setup();
void draw();
Carousel *carousel;
};
Line 10 in Carousel.m creates a local vector with size 20. If you want to set the size of Carousel::carouselSections to 20 you could do carouselSections.resize(20); or use the initializer syntax (or whatever it is called):
Cool, thanks, I have changed that. However, the size() call is still bad accessing on line 39 of Carousel.m... or Carousel.cpp as it's actually called, the comment is incorrect :)
Hmm. So if i declare the carousel as a class member in testApp.h, i can't initialize it in a method of testApp.cpp? Where could I initialize a member variable of a class and keep it in scope?