#include <iostream>
struct Index {
constexpr operator int() const { return 666; }
};
template <int i> void foo() {
std::cout << i << std::endl;
}
void wrapper(Index index) {
foo<index>();
}
int main() {
Index index;
// foo<index>(); // error: the value of ‘index’ is not usable in a constant expression
wrapper(index);
}
Run Code Online (Sandbox Code Playgroud)
大家好.
我正在使用变量"index"的constexpr转换为int值,该值替换为"foo"模板化函数.如果我直接foo<index>()从"main" 调用,我会收到编译器错误.如果从"包装器"完成相同的调用,那么一切都编译并正常工作.
我在那里错过了什么?
编译命令:g++ -std=c++14 main.tex使用g ++(GCC)5.3.1 20160406(Red Hat 5.3.1-6).
我试图查找有关属性路由的信息,发现有两种实现方式,但是我找不到任何区别。是否由于支持旧版本或其他功能而存在它们?谢谢!
ps代码可能不是很准确,因为我刚刚开始学习ASP。pps如果不清楚,我将尝试解释。
public class MyController : Controller
{
// APPROACH 1
[Route("api/books")]
[HttpGet]
public async List<Book> GetBooks()
{
// Implementation
}
// APPROACH 2
[HttpGet("api/books")]
public async List<Book> GetBooks()
{
// Implementation
}
}
Run Code Online (Sandbox Code Playgroud)