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)
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):
USING_NS_CC
from the top of implementation file.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.