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?
So confused!
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?
So confused!
Code:
// testApp.m
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
Carousel *carousel = new Carousel;
carousel->addSection(CarouselSection());
}
//--------------------------------------------------------------
void testApp::draw() {
carousel->draw();
}
Code:
// Carousel.m
#include <iostream>
#include "ofMain.h"
#include "carousel.h"
Carousel::Carousel()
{
activeSection = 0;
vector<CarouselSection> carouselSections (20);
}
void Carousel::addSection(CarouselSection section)
{
carouselSections.push_back(section);
}
void Carousel::moveLeft()
{
if (activeSection > 0) {
activeSection--;
}
}
void Carousel::moveRight()
{
if (activeSection < carouselSections.size()) {
activeSection++;
}
}
int Carousel::getActiveSection()
{
return activeSection;
}
void Carousel::draw()
{
for(int i=0; i<carouselSections.size(); i++)
{
cout << "number of sections: " << carouselSections.size() << endl;
CarouselSection section = carouselSections.at(i);
section.draw(i * 220);
}
}
Last edited: