I presume you’re code is within a non-static method on the class Start, yes? If not then the type of this is invalid.
Does onKeyReleased have the function declaration of void (EventKeyboard::KeyCode code, Event* event)?
Yeah, it seems that VS is less strict with the syntax. I started my first project in VS and all compiled fine, then I moved to Xcode and oh dear, so many errors popped up.
As for the code you posted, you missed the override keyword after bool init(), and the virtual before it is needed only if you subclass Start. Try fixing it, maybe that’s what causing the error.
(The function becomes bool init() override;).
In short you write lambdas as
[variables to capture](requested arguments if needed) -> returnType //If the return type is `void` you can skip the ` -> void`
{
your function's body
}
The reason for capturing variables is that when you have a function that has one or more local variables and creates the lambda, and inside the lambda you need to use those variables, generally when the lambda is executed they are gone, since the method has ended. The way around this is capturing the needed values inside the square brackets.
This is just a very simple explanation, and I skipped some details.
Remember that lambdas might turn out to be really, really, really useful sometimes, and it’s always good to know how they work and how to use them. Check out this great c++ tutorial about lambdas for more.
in your case the lambda is
[](EventKeyboard::KeyCode keyCode, Event *event)
{
//Function body
}
The cpp-tests runs fine under VS, now I’m trying with cmake but with -G"Visual Studio 12 2013" options, I’ve read on stack overflow that this could help… and also with -fpermissive
I feel like -fpermissive is not a great “tool” to use? Doesn’t it essentially mask or hide real issues. I guess if you must still use VS2013 it may be the case you need it in certain instances, but we use CC_CALLBACK, SEL_SELECTOR, and lambdas and VS2015 doesn’t complain … not saying you’re doing anything wrong, just some feedback.
Anyway, since I’m not helping much I’ll just ask one quick question. Have you tried creating a new project, setting up a single button using CC_CALLBACK_2 and checking if that compiles/works fine in CLion and VS2013?
You’re right about -fpermissive, it’s not a good choice but it works.
With a new project it’s the same, VS ok, both 2013 and 2015, CLion same error.
I’ve tried to complete recreate a project, using the step by step guide I’ve made here, with latest suggestions from @Alexander_Boriskov[Guide] Compiling Cocos2d-x with CLion
Now I can run my project flawlessly in CLion with CMake, it works, only got the problem using CC_CALLBACK.
But in the meantime I’m trying to use cocos v3.10, and I’ve seen the prebuilt feature that speed up the building process a lot.
The prebuilt libs are only for VS, so I think that I’ve to follow this path, even if I don’t like it.
For sure in future I can’t use the prebuilt with CLion.
Maybe I have to switch to resharper from Jetbrains, that I can use in VS for a more comfortable way to write code.
I started all this for the debug feature from Jetbrains that I prefer, but I can’t wait 30-40 seconds for every build in cmake so this time Microsoft wins
BTW. Anyway I think that VS use some kind of “flag” that is more permissive like the -fpermissive used in cmake, but my knowledge of this type of building process are few.
I thought I was running into this issue, but mine was different, and my own mistake. In my searches for answers I stumbled upon this report below. (I might add that “expression must be rvalue” seems to be a very atypical compiler error, normally it would be “expression must be lvalue”)
per jet brains trac issue CPP-5004: (forum won’t let me link to the report - but maybe try putting this manually in your browser: youtrack.jetbrains.com/issue/CPP-5004 )
CPP-5004 False error: Parameter mismatch expression must be rvalue on constructing std::thread
Is duplicated by: CPP-5075 CPP-5428
Relates to: CPP-5125 CPP-3615
Parent for: CPP-5075 CPP-5428
Subtask of: CPP-1644 #include
void foo() {}
int main() {
auto t = std::thread(foo);
}
The error says “Parameter type mismatch: Expression must be rvalue”. However, this is valid C++ code, it compiles and runs as expected.