在C++中,是否有一个Vector2类,如果是这样,我需要包含什么才能使用它?
我想用它来存储二维向量,例如粒子的位置或速度.
在C++中,我有一个双重包含问题:
文件stuffcollection.h
#pragma once
#ifndef STUFFCOLLECTION_H
#define STUFFCOLLECTION_H
#include "Stage.h"
class Stuffcollection {
public:
bool myfunc( Stage * stage );
};
#endif // STUFFCOLLECTION_H
Run Code Online (Sandbox Code Playgroud)
文件stage.h:
#pragma once
#ifndef STAGE_H
#define STAGE_H
#include "Stuffcollection.h"
class Stage {
// stuffcollection used in stage.cpp
};
#endif // STAGE_H
Run Code Online (Sandbox Code Playgroud)
编译器错误:
\Stuffcollection.h|(line were bool myfunc is declared)|error: 'Stage' has not been declared|
||=== Build finished: 1 errors, 0 warnings ===|
有人可以解释为什么会发生这种情况以及如何解决这个问题?我已经使用include guard和pragma一次预处理器指令,它只是不起作用.
(如果我#include "Stuffcollection.h"从stage.h中删除并注释掉在stage.cpp中使用它的相应行,那么我的其余代码就可以正常工作了.这真的只是在将Stuffcollection包含到舞台中时突然停止工作.)
PS:舞台只是一个例子,我几乎每隔一个文件都使用stuffcollection,每次我都遇到这个问题.
编辑:我按照建议,现在的问题是invalid use of incomplete type,即虽然给出的答案解决了循环依赖的问题,但他们没有解决我正在处理的问题.我的问题在 …
在C++中,如何从向量中删除元素?
对于(1),我已经尝试了以下,但我不太确定它是否做了应该做的事情(删除传递给removeItem()的项目),它看起来不是很优雅:
vector<Item*> items;
// fill vector with lots of pointers to item objects (...)
void removeItem(Item * item) {
// release item from memory
if (int i = getItemIdIfExists(item) != -1) {
items.erase (items.begin()+i);
}
}
int getItemIdIfExists(Item * item) {
// Get id of passed-in Item in collection
for (unsigned int i=0; i<items.size(); i++) {
// if match found
if (items[i] == item) return i;
}
// if no match found
return -1;
}
Run Code Online (Sandbox Code Playgroud) 我正在完成cocos2d-x SimpleGame项目,我被困在第5章,http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_5_-_How_to_Detect_the_Collisions.
我发现CCMutableArray不赞成使用CCArray.但是我如何修改以下内容,使其与CCArray一起使用(显然不支持模板)?
HelloWorldScene.h
cocos2d::CCMutableArray<cocos2d::CCSprite*> *_projectiles;
Run Code Online (Sandbox Code Playgroud)
HelloWorldScene.cpp
// in init()
// Initialize arrays
_projectiles = new CCMutableArray<CCSprite*>;
HelloWorld::~HelloWorld()
{
if (_targets)
{
_projectiles->release();
_projectiles = NULL;
}
}
HelloWorld::HelloWorld()
:_projectiles(NULL)
{
}
void HelloWorld::update(float dt)
{
CCArray *projectilesToDelete = new CCArray<CCSprite*>;
CCMutableArray<CCSprite*>::CCMutableArrayIterator it, jt;
for (it = _projectiles->begin(); it != _projectiles->end(); it++)
{
CCSprite *projectile = *it;
// (...)
}
// (...)
}
Run Code Online (Sandbox Code Playgroud) 在AngularJS中,如何在指令的属性中使用变量?
没有任何指令,这工作正常:
<a
href="#/fruits/{{ fruit.short }}/details"
title="Back to Fruit details">
Back
</a>
Run Code Online (Sandbox Code Playgroud)
现在有了指令,这不起作用:
<backButton
href="#/fruits/{{ fruit.short }}/details"
title="Fruit details">
</backButton>
MyApp.directive( 'backbutton', function()
{
return {
restrict: 'E',
link: function( scope, element, attrs )
{
var href = attrs.href;
var title = attrs.title;
console.log( "href = " + href ); // undefined
console.log( "title = " + title ); // Fruit details
element.html('<a href="' + href + '" title="Back to ' + title + '">Back</a>');
}
};
});
Run Code Online (Sandbox Code Playgroud)
该指令本身适用于例如href="#/fruits/novariableused" …
我今天开始使用Restangular和Node,在我的角度视图中尝试将新用户添加到用户列表时遇到了问题.
view.html
<input type="text" ng-model="app.user.name" />
<input type="button" ng-click="app.addUser( app.user )" />
<ul>
<li ng-repeat="user in app.users">
<strong>{{ user.name }}</strong>
<input type="button" ng-click="app.removeUser( user )" />
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
app.js
var baseUsers = Restangular.all( 'users' );
app.getUsers = function()
{
baseUsers.getList().then( function( res )
{
app.users = res;
});
};
app.getUsers();
app.addUser = function( newUser )
{
baseUsers.post( newUser ).then( function( res )
{
if( res.success == true )
{
// add new user to scope array
app.users.push( res.data ); // …Run Code Online (Sandbox Code Playgroud) 在创建shapchat(https://www.snadownload.com/)用户名时,我无法找到允许的字符.这里的任何人都可以分享他们的知识吗?
上下文:我正在创建一个用户名验证系统.
NB我尝试过support.snvertising.com - 但它没有提供有关用户名中允许的字符的信息.
在OpenGL中,我怎么能得出一个给定的百分比的的轮廓圆的?我该如何控制轮廓的厚度?
示例:如果百分比为100,则应绘制整圆的轮廓.如果百分比为50,则应绘制半圆的轮廓.
我已经尝试过以下方法,但问题在于它完成了lineloop,导致连接圆形轮廓的起点和终点的线.另外,它不会让我改变轮廓的厚度.
glBegin(GL_LINE_LOOP);
for (int i=0; i < (360/10*percent/10); i++) {
float degInRad = i*DEG2RAD;
glVertex2f(a+cos(degInRad)*r,b+sin(degInRad)*r);
}
glEnd();
Run Code Online (Sandbox Code Playgroud)
我很想让我的GL_POINTS圈起来,但我想知道是否有更好的方法?
在cocos2d-x中,以下代码段应该在延迟后运行回调函数.我需要做些什么来修复错误?
bool LoadingLevelScreen::initialise() {
// set up the time delay
CCDelayTime *delayAction = CCDelayTime::actionWithDuration(0.5f);
// perform the selector call
CCCallFunc *callSelectorAction = CCCallFunc::actionWithTarget(
this, callfunc_selector( LoadingLevelScreen::menuCallbackStart ) );
// run the action
this->runAction( CCSequence::actions(
delayAction, callSelectorAction, NULL ) );
}
void LoadingLevelScreen::menuCallbackStart(CCObject * pSender)
{
}
Run Code Online (Sandbox Code Playgroud)
编译器错误:
error C2440: 'type cast' :
cannot convert from 'void (__thiscall LoadingLevelScreen::* )(cocos2d::CCObject *)'
to 'cocos2d::SEL_CallFunc'
Pointers to members have different representations; cannot cast between them
Run Code Online (Sandbox Code Playgroud) 在Laravel中,如何在链接到路径时使用html-tags HTML::link_to_route()?
我的例子:
<li>
{{ HTML::link_to_route( "books_new", "New Book" ) }}
</li>
Run Code Online (Sandbox Code Playgroud)
我想做什么:
<li>
{{ HTML::link_to_route(
"books_new",
"<span class='icon-book'></span>New Book"
) }}
</li>
Run Code Online (Sandbox Code Playgroud)