Converting Cocos2d code to ARC issues - cocos2d-iphone

I am trying to ARC enable a project and I am having a few issues when selecting files for ARC.
In the Ball class, the following line,
ballBody->SetUserData(self);
gives the error,
Cannot initialize a parameter of type 'void *' with an Ivalue of type 'Ball *const__strong'
In the Enemy.mm class, the following line,
enemyBody->SetUserData(enemySprite);
gives the error,
Cannot initialize a parameter of type 'void *' with an Ivalue of type 'CCPhysicsSprite*__strong'
In Enemy.h I have defined the above as:
b2Body* enemyBody;
CCPhysicsSprite* enemySprite; (in Enemy.m)
How can I solve these issues?

Bridge casting:
ballBody->SetUserData((__bridge void*)self);
enemyBody->SetUserData((__bridge void*)enemySprite);
and the reverse:
CCPhysicsSprite* enemySprite = (__bridge CCPhysicsSprite*)enemyBody->GetUserData();

Related

UE4 setting sprite by using C++

I didn't figure out how can i set a sprite in actor class constructor by using its reference.
Reference is "PaperSprite'/Game/cc/combat/units/archer_Sprite_0.archer_Sprite_0'"
I want to make this sprite static. I think should use ConstructorHelpers::FObjectFinder . When i run the code below, i got this error:
sprite = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Sprite_comp"));
sprite->SetupAttachment(RootComponent);
ConstructorHelpers::FObjectFinder<UPaperSprite> SpriteAssetObj(TEXT("PaperSprite'/Game/cc/combat/units/archer_Sprite_0.archer_Sprite_0'"));
//sprite->SetSprite(SpriteAssetObj.Object);
"Severity Code Description Project File Line Suppression State
Error C2664 'void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)': cannot convert argument 1 from 'T *' to 'UObject *' MyProject C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\CoreUObject\Public\UObject\ConstructorHelpers.h 110
"
Any help or advice would be nice. Thanks in advance.
I want to make this sprite static.
ConstructorHelpers::FObjectFinder is for finding an asset.
In case of movement would be:
sprite->SetMobility(EComponentMobility::Type::Stationary);
I tested the code below without any problem. Are you sure ConstructorHelpers::FObjectFinder... is causing the error?
static ConstructorHelpers::FObjectFinder<UPaperSprite> SpriteAssetObj(TEXT("PaperSprite'/Game/TEMP/Sprites/SP_TempSprite_1.SP_TempSprite_1'"));
if (SpriteAssetObj.Object)
{
UE_LOG(LogTemp, Warning, TEXT("PaperSprite loaded"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("PaperSprite not found"));
}
Don't forget to add Paper2D module to your YourGame.build.cs file:
PublicDependencyModuleNames.AddRange(new string[] { "Paper2D" });
And add to your file:
#include "PaperSprite.h"

Does anyone know why it happens? C++ 'initializing': cannot convert from

So this is my header to a class:
#include <iostream>
class Board
{
public:
Board();
AllPieces* GetBoard();
void createBoard();
protected:
AllPieces** everything= new (AllPieces**)[32];
};
But when I try to initialize the 'everything' array, it says this error:
Error C2440 'initializing': cannot convert from 'AllPieces ***' to 'AllPieces **'
I don't know why it says that, what I want to do is to make an array of pointers from the class AllPieces.
Can anybody help me please? thank you
The code new (AllPieces**)[32] creates a pointer to an object of type AllPieces**, which thus has a type of AllPieces***. If you drop one of the *, you will get the correct return type.
To eliminate the error, change the line in question to:
AllPieces** everything = new AllPieces*[32];

Error in TinyXml++ tutorial

trying to compile the TinyXml++ tutorial with CodeBlocks (16.01) and with VS2013 I get the same error at following line:
ticpp::Element* pElem = doc.FirstChildElement()->NextSibling();
CodeBlocks error:
invalid conversion from 'ticpp::Node*' to 'ticpp::Element*'
[-fpermissive]
VS2013 error:
cannot convert from 'ticpp::Node *' to 'ticpp::Element *'
Any idea?
In case you still want to compile it, regardless of whether there is an error in the tutorial, you can use the auto keyword for variable declaration.
For example:
auto pElem = doc.FirstChildElement()->NextSibling();
This way, the compiler will deduce the variable type at compile time.
The return type of NextSibling() is Node*. If you want Element* as return type, you can use NextSiblingElement() instead.

Type/Value Mismatch error while declaring a vector of custom class in c++

In my header file, I have a custom class called Arc declared like this
class Arc{
public:
Point start, end, centre;
//an arc is specified with its centre , starting point and end point
float radius, sweep, theta;
//radius of the arc and the angle enclosed by the arc are specified
int direction;
//whether the arc is formed in the clockwise direction or the anticlockwise direcn is specfied
Arc();
Arc(Point, Point, Point, int);
void draw();
// draws the arc on the GLUT canvas
int nextDirection(Point);
// finds the direction of the arc formed by joining the end point of this arc and a new point
};
I want to create a vector of this custom class . I declare a vector like this:
extern vector<Arc> arcs;
This line gives the following 4 errors.
error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'|
error: expected a type, got 'Arc'|
error: template argument 2 is invalid|
error: invalid type in declaration before ';' token|
I read on another answer that such a declaration needs a default constructor inside the class which i have added. but still same errors occur
Note: It builds successfully on Ubuntu14.04 using g++ compiler. But when trying to build in Code::Blocks on Windows 8.1 using mingw-g++ it gives this error.

gluTessCallback error C2440

I am trying to use the function gluTessCallback but I get C2440 error. I have no idea why.
Here is the code:
#define callback void(CALLBACK*)()
template<typename T>
class Tessellation
{
private:
GLUtesselator *pTess;
void CALLBACK tessError(GLenum error)
{
sendErrorMessage((char *)gluErrorString(error), true);
}
public:
void Triangulation3D(T* & point, short numOfPoints)
{
pTess = gluNewTess();
gluTessCallback(pTess, GLU_TESS_ERROR, (callback)tessError);
}
};
The error is on gluTessCallback function:
error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'void (__stdcall *)(void)'
Why do I get this compile error?
The error id C2440 on Visual Studio is a type conversion error.
The problem in your code is that you are trying to pass a class method Tessellation::tessError() as function pointer to gluTessCallback(), which expects a pointer to a global C-style function.
A class method is very different from a free/global function and you cannot pass it as a simple function pointer because it needs an object to go along with it every time, the this pointer.
A solution to your problem would be to declare tessError() as a static method, making it effectively the same as a free/global function scoped inside the class, like so:
template<typename T>
class Tessellation
{
private:
static void CALLBACK tessError(GLenum error)
{
sendErrorMessage((char *)gluErrorString(error), true);
}
...
And pass it to gluTessCallback():
gluTessCallback(pTess, GLU_TESS_ERROR, (callback)&Tessellation<T>::tessError);
The only downside to this approach is that a static tessError() can no longer access class variables. Which doesn't seem like a problem to you, since it is not doing so right now, it appears.