想象一下,旋转会导致纹理的调色板从屏幕的一边滚动到另一边。我们将随机选择在给定矩形内的纹理,以模仿旋转图像的功能。
//Header file of the Texture Embedded. This is Fabric.h
class Fabric: public WhirligigNetwork {
.....
........
void initFabric(void);
public:
static Fabric * create();我静态地初始化了主对象:
//In Fabric.cpp
//Fabric create function.
Fabric * Fabric::create() {
Fabric * fabric = new Fabric();
if (fabric && fabric-> initWithSpriteFrameName("fabric.png")) {
fabric->autorelease();
fabric->initObstacle();
return fabric;
}
CC_SAFE_DELETE(fabric);
return NULL;
}不幸的是,当我试图扩展' Fabric‘(它是类CCSprite上的一个掩码)并编译时,Xcode很难弄清楚Fabric到底是什么。*困惑
/*So let's say that we're implementing a randomized selection of fabric elements that are
assigned to a whirligig of Sprite 'containers'.*/
class WhirligigNetwork : public Sprite {
.................
.......................
//Xcode does not know type name (Fabric) - the override is useless.
//An Array of Fabrics!
cocos2d::Vector<cocos2d::Sprite *> _fabrics;
void initFabric(Fabric * fabrics); /* doesn't run */
/* If I play around with inline helper methods to query for a countable set of widths*/
inline float getWideness() {
//then I order and count the elements of my Vector<T>
int count = _fabrics.size();
//Default
int wideness = 0;
//Deal with the heap.
class Fabric * fabrics;
for (int i = 0; i < count; i++) {
fabric = (class Fabric *) _fabics.at(i);
// set-increment wideness
wideness += fabric->getWideness();
}
return wideness;
}成员进入不完全类型的“类结构”.有什么建议吗?
发布于 2014-05-21 14:13:58
你有一个循环依赖关系。
您需要在定义Fabric之前定义类WhirligigNetwork,但是不能这样做,因为Fabric需要首先定义WhirligigNetwork。
简单的解决方案是在Fabric定义之前声明类WhirligigNetwork,然后将成员函数实现放在一个单独的源文件中,您可以安全地按正确的顺序包含这两个头文件。
因此,在WhirligigNetwork的头文件中有。
#ifndef WHIRLIGIGNETWORK_H
#define WHIRLIGIGNETWORK_H
// Declare the class Fabric
class Fabric;
// Define the class WhirligigNetwork
class WhirligigNetwork : public Sprite
{
private:
cocos2d::Vector<cocos2d::Sprite *> _fabrics;
...
public:
...
float getWideness();
...
};
#endif以及WhirligigNetwork源文件中的
#include "whirligignetwork.h"
#include "fabric.h"
// Can use `Fabric` freely in here
...
float WhirligigNetwork::getWideness()
{
...
}https://stackoverflow.com/questions/23785451
复制相似问题