我和我的一位同事讨论过关于他人的问题
Pt pt;
Run Code Online (Sandbox Code Playgroud)
和
Pt pt = Pt();
Run Code Online (Sandbox Code Playgroud)
是等价的.我怀疑在第二种情况下可以调用复制分配,但事实证明并非如此.
当我们进行我们的小实验时,我决定测试一个奇怪的位,我的同事认为甚至不会编译:
//here the compiler calls a copy constructor and doesn't call the default constructor prior to that
// O_o
Pt pt = pt;
Run Code Online (Sandbox Code Playgroud)
以下是一个工作示例:http://ideone.com/XmJSz7
所以,问题是 - 发生了什么:
Pt pt = pt;
Run Code Online (Sandbox Code Playgroud) 基本上C++ 11中有三种类型的演绎:
auto
decltype
对于大多数情况,类型推导auto
和模板似乎以相同的方式起作用.但有一种情况 - 当我们将auto
变量设置为由括号封闭的{}初始化程序生成的值时,我们会得到编译错误
no match for call to '(std::initializer_list<int>) (<brace-enclosed initializer list>)' foo({0, 1, 2, 3});
Run Code Online (Sandbox Code Playgroud)
以下是代码实时示例的链接:http: //ideone.com/ODBAZ5
//foo's type would be deduced as std::initializer_list<int>
auto foo = {0, 1, 2, 3};
template<typename T>
void bar(T t){};
//compiles fine
bar( foo );
//next line gives compiler error
bar({0, 1, 2, 3});
Run Code Online (Sandbox Code Playgroud)
decltype
是一个完整的另一个故事,并且在这个问题的旁边,但是auto
模板应该做同样的事情(至少那些看似合理的东西),当推断出类型时 - 但是它们显然不会,而且它会让人感到困惑为什么?
我需要检查apk中是否存在某个目录.
该android/asset_manager.h
API似乎是不一致的-当它返回NULL AAsset* AAssetManager_open(AAssetManager* mgr, const char* filename, int mode);
无法打开文件,但目录AAssetDir* AAssetManager_openDir(AAssetManager* mgr, const char* dirName);
的实现总是返回new AAssetDir(...)
,即使在内部它无法打开/找到的apk的目录.
AAssetDir
前向声明并且它的实现隐藏在.cpp文件中是非常恼人的,否则它(可能?)可能检查内部AssetDir
对象的有效性.
我现在正在探索另一个选项 - 调用java并执行以下操作:
public static boolean folderExistsInApk(final String path){
AssetManager assetManager = activity.getAssets();
try{
//if .list would fail, it would throw IOException
//which would signal that there is no such directory
assetManager.list(path);
}catch(Exception e){
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
但它对我来说似乎"脏",它肯定会很慢(这不是我特定代码中的一个重要因素,但仍然 - 避免不必要的悲观化是良好的编码实践).
我错过了什么吗?是否可以通过本机代码检查apk中是否存在目录?如果不是 - 如何最好地使用jni?
我希望Unity 4.6中的RectTransform(面板)遵循worldObject。我完成了这项工作,但动作并不如我所愿。当我开始移动相机时,它似乎有些参差不齐,并且落后了。
Vector2 followObjectScreenPos = Camera.main.WorldToScreenPoint (planet.transform.position);
rectTransform.anchoredPosition = new Vector2 (followObjectScreenPos.x - Screen.width / 2, followObjectScreenPos.y - Screen.height / 2);
Run Code Online (Sandbox Code Playgroud)
提示和技巧非常感谢。:-)