Reference ambiguous to Cocos2d-x Size type

I want to implement some objective c calls in c++ project i.e. Am trying to do same thing as "this question" (compile some specific files as objective c++)

but then i get into "Reference ambigious" errors for this line of code :

Size visibleSize = Director::getInstance()->getVisibleSize();

saying "Reference to 'Size' is ambigious"

my current compiler settings:

C Lang Dialect : GNU99[-std=gnu99]
Compiler Sources As : According to File Type

C++ Language Dialect : GNU++14[-std=gnu99]
C++ Standard Library : libc++ (LLVM C++ standard library with c++11 support)

Answers


The issue is that the Size type exists in Cocos2d-x and somewhere else in the header files the compiler has seen.

Luckily all of Cocos2d-x is defined in its own namespace, so you need to do the following in the offending file(s):

  1. Remove USING_NS_CC from the top of implementation file.
  2. Add the cocos2d:: namespace to any Cocos2d-x type and class references in the implementation file, for example:

    cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
    

That tells the compiler exactly which Size type you are referring to.

Also Cocos2d-x supports C++11 but not C++14 as far as I know, so change that in the build settings.


Need Your Help

Exporting data with Display Tag and external pagination

java jsp reporting export-to-excel displaytag

We use the Display Tag Library to display grid data in our JSP's.

Passing a JavaScript variable in SQL Datasource in ASP.Net C#

c# javascript asp.net data-binding

I have a java script variable and I want to use it into my sqldatasourse how can I do this. Here is my java script code