Pass sprite to function cocos2dx - c++

I am making pong in cocos2dx and would like to make a function that would take a sprite as an input together with the direction of movement. VC2012 spits out an error on compilation
Error 1 error C2061: syntax error : identifier 'Sprite' (..\Classes\AppDelegate.cpp)
Error 2 error C2061: syntax error : identifier 'Sprite' (..\Classes\HelloWorldScene.cpp)
Error 4 error C2660: 'HelloWorld::movePaddle' : function does not take 2 arguments
Error 5 error C2511: 'void HelloWorld::movePaddle(cocos2d::Sprite *,int)' : overloaded member function not found in 'HelloWorld'
Here is the function:
void HelloWorld::movePaddle(Sprite *paddle, int direction) {
paddle->runAction(MoveBy::create(1,Point(0,15*direction)));
}
Here is the function prototype in the .h file:
void HelloWorld::movePaddle(Sprite *paddle, int direction);
What am I doing wrong?
I apologise if this question seems stupid, I'm very new.

Related

startEnc function wont accept any object as a parameter

This is the error I'm getting:
Encounter.h(5,26): error C2061: syntax error: identifier 'TestEnemy'
Encounter.cpp(10,1): error C2511: 'void Encounter::startEnc(TestEnemy)': overloaded member function not found in 'Encounter'
Hero and TestEnemy are classes I've defined in other h and cpp files
Encounter.h:
#pragma once
class Encounter
{
public:
void startEnc(Hero player, TestEnemy e1);
};
Encounter.cpp:
void Encounter::startEnc(Hero player, TestEnemy e1)
{
...
}
I suppose the error could be from another part of my code but visual studio seems to suggest that it's something to do with these. I'll share more code if need be; I just didn't want to inflate this post.

Passing unique pointer child as a reference

VulkanSurface.h:
#include "VulkanInstance.h"
class VulkanSurface {
public:
//Only constructor
VulkanSurface(VulkanInstance &instance); //line 14
};
VulkanSurface.cpp:
VulkanSurface::VulkanSurface(VulkanInstance &instance) {
//...
}
VulkanInstance.cpp:
VulkanInstance::VulkanInstance(const std::vector<const char*> validationLayers) :
validationLayers(validationLayers) {
...
}
main.cpp:
instance = std::make_unique<VulkanInstance>(validationLayers);
surface = std::make_unique<VulkanSurface>(*instance); //line 104
This shows no errors in VisualStudio in form of red squiggly line, but the compilation fails with the following:
1>main.cpp
1>c:\users\karlovsky120\source\repos\vulkanproject\vulkanproject\vulkansurface.h(14): error C2061: syntax error: identifier 'VulkanInstance'
1>c:\users\karlovsky120\source\repos\vulkanproject\vulkanproject\main.cpp(104): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'VulkanSurface'
1>c:\users\karlovsky120\source\repos\vulkanproject\vulkanproject\main.cpp(104): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\karlovsky120\source\repos\vulkanproject\vulkanproject\main.cpp(104): error C2672: 'std::make_unique': no matching overloaded function found
1>VulkanInstance.cpp
1>c:\users\karlovsky120\source\repos\vulkanproject\vulkanproject\vulkansurface.h(14): error C2061: syntax error: identifier 'VulkanInstance'

Can't compile boost/any_iterator.hpp in boost 1.57

After (attempting to) upgrade a VS2012 project to use boost 1.57, I can no longer compile--lots and lots of error messages coming out of boost/any_iterator.hpp (see below). As a test, I created a new project that contained nothing but an empty main function and #include "boost/any_iterator.hpp" and got the same set of errors. Here is the code it's complaining about:
// snippet from boost/any_iterator.hpp
template<
class Value
, class Traversal
, class Reference
, class Difference
, class Buffer
>
class postfix_increment_proxy<
range_detail::any_iterator< // line 131
Value
, Traversal
, Reference
, Difference
, Buffer
>
>
{
// ...
};
There is another class in the same file that follows the same pattern and generates identical errors. range_detail::any_iterator is forward-declared a little higher up in the file:
namespace range_detail
{
// ...
template<
class Value
, class Traversal
, class Reference
, class Difference
, class Buffer = any_iterator_default_buffer
>
class any_iterator;
// ...
}
For what it's worth, here's the set of errors I get from VS2012:
Error 1 error C2143: syntax error : missing ';' before '<' [path]\boost\range\detail\any_iterator.hpp 131
Error 2 error C2059: syntax error : '<' [path]\boost\range\detail\any_iterator.hpp 131
Error 3 error C2065: 'Value' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 134
Error 4 error C2065: 'Traversal' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 135
Error 5 error C2065: 'Reference' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 136
Error 6 error C2065: 'Difference' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 137
Error 7 error C2065: 'Buffer' : undeclared identifier [path]\boost\range\detail\any_iterator.hpp 138
Error 8 error C2923: 'boost::range_detail::any_iterator' : 'Value' is not a valid template type argument for parameter 'Value' [path]\boost\range\detail\any_iterator.hpp 138
Error 9 error C2923: 'boost::range_detail::any_iterator' : 'Traversal' is not a valid template type argument for parameter 'Traversal' [path]\boost\range\detail\any_iterator.hpp 138
Error 10 error C2923: 'boost::range_detail::any_iterator' : 'Reference' is not a valid template type argument for parameter 'Reference' [path]\boost\range\detail\any_iterator.hpp 138
Error 11 error C2923: 'boost::range_detail::any_iterator' : 'Difference' is not a valid template type argument for parameter 'Difference' [path]\boost\range\detail\any_iterator.hpp 138
Error 12 error C2923: 'boost::range_detail::any_iterator' : 'Buffer' is not a valid template type argument for parameter 'Buffer' [path]\boost\range\detail\any_iterator.hpp 138
Error 13 error C2143: syntax error : missing ';' before '{' [path]\boost\range\detail\any_iterator.hpp 140
Error 14 error C2447: '{' : missing function header (old-style formal list?) [path]\boost\range\detail\any_iterator.hpp 140
Is anyone aware of a workaround?
This appears to be a bug in the boost codebase. postfix_increment_proxy and writable_postfix_increment_proxy are both in the boost::iterators::detail namespace (iterator_facade.hpp). However, both names are used unqualified in any_iterator.hpp. Adding boost::iterators::detail:: in front of both names allows the code to compile.
For anyone who's uncomfortable with the idea of editing boost code, including iterator_facade.hpp followed by using namespace boost::iterators::detail followed by an include for any_iterator.hpp will also solve the problem at the cost of namespace pollution. VS2012 doesn't support them so it doesn't do me any good, but you could presumably use a C++11 using too.
Ticket submitted:
https://svn.boost.org/trac/boost/ticket/10754

Syntax errors when passing string argument onto function

Visual Studio (2012/C++) is reporting multiple errors all relaxing to errors in syntax when I cannot see any errors.
I'm calling the function with Ping(ID); and ID is a string (Already defined), I've defined the function in the relevant header file as
#include <string>
int Ping(string ID);.
A stripped down version of the function is
int Ping(string ID)
{
// Ping
cout<<"Pinging\n";
cout<<ID;
return (1);
}
and the errors in the header file are as follows;
Error 3 error C2059: syntax error : ')' func.h 3 1
Error 1 error C2065: 'string' : undeclared identifier func.h 3 1
Error 2 error C2146: syntax error : missing ')' before identifier 'ID' func.h 3 1
I'm really stuck with what I need to do to fix this, so any guidance on how to fix it will be greatly appreciated.
You did not qualify the name with std::, as std::string.

Converting from var to var&

How can I convert a variable of type var or var* to var&
I've to use a function which takes an object of var class(suppose there's a class). The example code was given like this:-
testFunc(false, namespace1::namespace2::var(), 100);
in function declaration it says that the second parameter is of type namespace1::namespace2::var&, I can create namespace1::namespace2::var or namespace1::namespace2::var*, but how do I create namespace1::namespace2::var&?
I know that's too basic question but I couldn't figure it out.
Edit:
I've tried using just var, but it gives some odd errors. I am pretty sure that's some kind of fault in the function I am using. Here're the errors:-
Error 3 error C2825: 'CType': must be a class or namespace when followed by '::'
Error 4 error C2039: 'TypeCode' : is not a member of '`global namespace''
Error 5 error C2146: syntax error : missing ',' before identifier 'TypeCode'
Error 6 error C2065: 'TypeCode' : undeclared identifier
Error 7 error C3203: 'CustomType' : unspecialized class template can't be used as a template argument for template parameter 'Base', expected a real type
Edit 2
I thought it'd be hard to answer if I include real code, since it's complicated. But have a look if it helps. The real function's signature is like this:-
virtual bool opRaiseEvent(bool reliable, const Common::Hashtable& parameters, nByte eventCode, nByte channelID=0, int* targetPlayers=NULL, short numTargetPlayers=NULL);
and the example code used the function like this:-
mLoadBalancingClient.opRaiseEvent(false, ExitGames::Common::Hashtable(), 100);
which was working fine. But now I want to add data to the HashTable, so I need to create an object of it and then pass it to the function. It's not accepting a pointer or normal variable. I don't know why it's working with just HashTable().
It means the second parameter is passed by reference. You have to simply pass:
namespace1::namespace2::var
This should work :
const Common::Hashtable param = namespace1::namespace2::var();
opRaiseEvent(false, param, 100);
namespace1::namespace2::var v;
testFunc(false, v, 100);