让我解释一下这种情况:无法获得的另一种载体内从矢量数据
我有一个类cAnimation有几个方法
#include "SDL/SDL.h"
#include <vector>
#include <fstream>
using namespace std;
class cAnimation{
private:
vector<SDL_Rect> frames;
public:
cAnimation();
void setQntFrames(int n){
this->frames.resize(n);
ofstream log("qntframes.txt");
log << "capacity = " << this->frames.capacity();
}
void setFrame(int index,int x, int y, int w, int h){
this->frames[index].x = x;
this->frames[index].y = y;
this->frames[index].w = w;
this->frames[index].h = h;
ofstream log("setrect.txt");
log << "i = " << i
<< "x = " << this->frames.at(i).x
<< "y = " << this->frames.at(i).y
<< "w = " << this->frames.at(i).w
<< "h = " << this->frames.at(i).h;
}
SDL_Rect cAnimation::getFrame(int index){
return this->frames[index];
}
};
我在我的main.cpp这样做(在包括都行)
vector<cAnimation> animation;
animation.resize(1);
animation[0].setQntFrames(10); // it's printing the right value on qntframes.txt
animation[0].setFrame(0,10,10,200,200) // it's printing the right values on setrect.txt
SDL_Rect temp = animation[0].getFrame(0);// here is the problem
ofstream log("square.txt");
log << "x = " << temp.x
<< "y = " << temp.y;
当我看向square.txt日志
,看起来像正方形一些奇怪的字符,当我尝试去SDL_Rect临时的数据使用,应用刚刚结束,我在做什么这里弄错了值?
请阅读http://sscce.org,了解如何以及为什么您应该将代码减少到一个简单的测试用例。 – 2012-03-20 17:22:35