小编Jes*_*der的帖子

使用C++中的模板混淆函数查找

从以下开始(使用gcc version 4.0.1):

namespace name {
   template <typename T>
   void foo(const T& t) {
      bar(t);
   }

   template <typename T>
   void bar(const T& t) {
      baz(t);
   }

   void baz(int) {
      std::cout << "baz(int)\n";
   }
}
Run Code Online (Sandbox Code Playgroud)

如果我添加(在全局命名空间中)

struct test {};
void bar(const test&) {
   std::cout << "bar(const test&)\n";
}
Run Code Online (Sandbox Code Playgroud)

然后,正如我所料,

name::foo(test()); // produces "bar(const test&)"
Run Code Online (Sandbox Code Playgroud)

但是,如果我只是添加

void bar(const double&) {
   std::cout << "bar(const double&)\n";
}
Run Code Online (Sandbox Code Playgroud)

它似乎无法找到这个重载:

name::foo(5.0) // produces "baz(int)"
Run Code Online (Sandbox Code Playgroud)

更重要的是,

typedef std::vector<int> Vec;
void bar(const Vec&) { …
Run Code Online (Sandbox Code Playgroud)

c++ lookup templates

3
推荐指数
1
解决办法
971
查看次数

如何防止我的应用程序在iPhone上的后台运行

当按下主页按钮时,有没有办法让应用程序退出而不是去后台?出于安全原因,如果应用程序不在后台运行但在推送主页时实际关闭会更好.这不是用户的安全性,而是用于应用程序上的公司数据,因此不是用户的选择.除了强迫退出之外,我找不到任何退出方式,苹果不鼓励这样做.

iphone

3
推荐指数
1
解决办法
3925
查看次数

如何在std :: remove_if之后使用"removed"元素

说我们有:

struct IsEven {
   bool operator() (int i) { return i % 2 == 0; }
};
Run Code Online (Sandbox Code Playgroud)

然后:

vector<int> V; // fill with ints
vector<int>::iterator new_end = remove_if(V.begin(), V.end(), IsEven());
V.erase(new_end, V.end());
Run Code Online (Sandbox Code Playgroud)

工作得很好(它只留下V奇数整数).但似乎从元素new_endV.end()不是我们正在删除偶数.例如,如果v以as开头1 4 2 8 5 7,那么我就会得到8 5 7这些元素(尽管在erase调用之后,向量确实已经1 5 7离开了).

显然,(根据http://www.sgi.com/tech/stl/remove_if.html)

The iterators in the range [new_last, last) are all still dereferenceable,
but the elements that they point …
Run Code Online (Sandbox Code Playgroud)

c++ stl

2
推荐指数
1
解决办法
758
查看次数

有没有办法在标准C++中直接从键盘读取输入?

我知道有std::cin,但这需要用户输入一个字符串,然后按ENTER键.有没有办法简单地获得推送的下一个键,而无需按ENTER确认

c++ keyboard console input

2
推荐指数
1
解决办法
3242
查看次数

在Objective-C中将unsigned char*转换为int*

我试图在iPhone上的Objective-C中将a转换unsigned char*int *on.有没有可以帮助转换的API?

这是我最好的尝试:

-(BOOL)MyFunc:Version:(int *)nVer
{
   unsigned char * uszVerSize;
   //trying to assign string to int
   nVer =  uszVerSize[0] ;
}
Run Code Online (Sandbox Code Playgroud)

iphone

2
推荐指数
1
解决办法
1万
查看次数

返回本地引用或指针时的行为差异

#include <iostream.h>
using namespace std;

class A {
public:
   virtual char* func()=0;
};

class B :public A {
public:
   void show() {
      char * a;
      a = func();
      cout << "The First Character of string is " << *a;
   }
   char * func();
};


char* B::func() {
   cout << "In B" << endl;
   char x[] = "String";
   return x;
}

int main() {
   B b;
   b.show();
}
Run Code Online (Sandbox Code Playgroud)

这个问题是我正在修复本地varibale指针/引用.目前它是char x[]="String",但是当我使用指针时char *x="String",结果是"S" 但当数组引用时输出为(i)

c++

2
推荐指数
1
解决办法
191
查看次数

使用Xcode为iPhone编译*时内存泄漏日志消息

当我编译我的iPhone项目(在命令行中)时,日志输出如下所示:

2009-11-05 22:19:57.494 xcodebuild[51128:613] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler 'com.apple.compilers.llvm.clang.1_0.analyzer'
=== BUILDING NATIVE TARGET Foo OF PROJECT foo WITH THE DEFAULT CONFIGURATION (AdHoc) ===

Checking Dependencies...
2009-11-05 22:19:58.032 xcodebuild[51128:5b07] *** _NSAutoreleaseNoPool(): Object 0x722d410 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x97257f4f 0x97164432 0xfea624 0x2620e34 0x2620cbd 0x2384304 0x23957a3 0x948b76f0 0x948b8d35 0x948ae3c5 0x948aeaa8 0x2620922 0x9716adfd 0x9716a9a4 0x926bd155 0x926bd012)
2009-11-05 22:19:58.035 xcodebuild[51128:5b07] *** _NSAutoreleaseNoPool(): Object 0x720b370 of class NSCFDictionary autoreleased with no pool in …
Run Code Online (Sandbox Code Playgroud)

iphone xcode memory-leaks compilation

1
推荐指数
1
解决办法
1212
查看次数

无效的标量十六进制值0x8000000及以上

我发现从yaml文件获取十六进制值时出现问题.它无法获得十六进制值0x80000000及以上.以下是一个示例C++程序.

// ymlparser.cpp
#include <iostream>
#include <fstream>
#include "yaml-cpp/yaml.h"

int main(void)
{
  try {
    std::ifstream fin("hex.yaml");
    YAML::Parser parser(fin);
    YAML::Node doc;
    parser.GetNextDocument(doc);

    int num1;
    doc["hex1"] >> num1;
    printf("num1 = 0x%x\n", num1);

    int num2;
    doc["hex2"] >> num2;
    printf("num2 = 0x%x\n", num2);
    return 0;
  } catch(YAML::ParserException& e) {
    std::cout << e.what() << "\n";
  }
}
Run Code Online (Sandbox Code Playgroud)

hex.yaml

hex1: 0x7FFFFFFF
hex2: 0x80000000
Run Code Online (Sandbox Code Playgroud)

错误信息在这里.

$ ./ymlparser 
num1 = 0x7fffffff
terminate called after throwing an instance of 'YAML::InvalidScalar'
  what():  yaml-cpp: error at line 2, column 7: invalid …
Run Code Online (Sandbox Code Playgroud)

c++ yaml-cpp

1
推荐指数
1
解决办法
1263
查看次数

有没有办法在iOS 4中禁止多任务?

我希望我的应用程序在用户点按主页按钮时退出,而不会进入后台.这可能吗?

iphone multitasking

1
推荐指数
1
解决办法
115
查看次数

如何在分析时在bazel中运行shell命令?

我正在尝试将mercurial版本烘焙到我的Bazel文件中,以便我可以得到这样的东西:

# These I set manually, since they're "semantic"
MAJOR_VERSION = 2
MINOR_VERSION = 3
BUGFIX_VERSION = 1

# This should be the result of `hg id -n`
BUILD_VERSION = ?

apple_bundle_version(
    name = "my_version",
    build_version = "{}.{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, BUGFIX_VERSION, BUILD_VERSION),
    short_version_string = "{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, BUGFIX_VERSION),
)
Run Code Online (Sandbox Code Playgroud)

这显然不是密封的,所以我知道这违反了Bazel的一些假设,所以我对其他选择持开放态度.

这里有一些可能的选择:

  1. 实际上hg id -n在Bazel分析期间运行,我不知道该怎么做.

  2. 在via命令行中传递构建版本,例如--define=build_version=$(hg id -n).不幸的是,这需要一个单独的命令来包装bazel build.

  3. 手动设置BUILD_VERSION.显然,这会很烦人.

有没有办法做#1?我还有什么其他选择?

versioning bazel

1
推荐指数
1
解决办法
1295
查看次数