小编Car*_*nta的帖子

在构造函数上指定constexpr会自动使从它创建的所有对象都是constexpr吗?

这是我的代码:

class test{
    public:
    constexpr test(){

    }

    constexpr int operator+(const test& rhs){
        return 1;
    }
};



int main(){

    test t;                         //constexpr word isn't necessary
    constexpr int b = t+test();     // works at compile time!


    int w = 10;                     // ERROR constexpr required
    constexpr int c = w + 2;        // Requires w to be constexpr
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我注意到即使我没有指定测试,它仍然有效constexpr.我尝试通过执行相同的方式复制结果,int但我得到错误.具体来说,它希望我的int w内心constexpr int c = w + 2;成为constexpr.从我第一次尝试使用test,它是否工作,因为我constexpr已经在构造函数上使用的原因?如果是这种情况,那么假设 …

c++ language-lawyer constexpr c++11

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

在struct中初始化静态constexpr变量和类

这是我的工作代码示例:

#include <iostream>

template<typename B>
class b {
public:
    int y;

    constexpr b(int x) : y(x) {

    }

    constexpr void sayhi() {
        std::cout << "hi" << std::endl;
    }
};



template<int x>
struct A {
    static constexpr b<int> bee = x;
    static constexpr int y = x;         // this one is fine and usable already, I don't have to do something like what I did on member bee

    inline static void sayhi() {
        std::cout << y << std::endl;
    }
};

template<int …
Run Code Online (Sandbox Code Playgroud)

c++ struct constexpr

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

以编程方式定义类:type vs types.new_class

除了types.new_class在创建类时定义关键字参数的能力.这两种方法之间是否存在重大差异?

import types

First = type('First',(object,),{'asd':99})
k = First()

Second = types.new_class('Second',(object,),{},lambda x:x)
x = Second()
Run Code Online (Sandbox Code Playgroud)

python

7
推荐指数
2
解决办法
868
查看次数

将IPagedList与复选框绑定为List

所以..我有一个有一个类List.我把它传递给视图,如下面的代码:

[HttpGet]
[Authorize(Roles="user")]
[CustomChecker]
public ActionResult Index(int? page, int id=0)
{
    EmployeeContext emp = new EmployeeContext();
    student st = emp.students.Single(x=>x.id ==id);

    @ViewBag.id = st.id;

    return View(st.subjSel.ToPagedList(page ?? 1, 4));
}
Run Code Online (Sandbox Code Playgroud)

然后View会像这样收到它:

@using PagedList;
@using PagedList.Mvc;
@model PagedList<MvcApplication6.Models.subject>
<div style="font-family:Arial">
    <fieldset>
        <legend><h3>Open Classes</h3></legend>
        @using (Html.BeginForm("Test", "Enrollment"))
        {
            <input type="hidden" name="id" value="@ViewBag.id" />
            <table border="1">
                <tr>
                    <th>@Html.LabelFor(model => model[0].subj)</th>
                    <th>@Html.LabelFor(model => model[0].days)</th>
                    <th>@Html.LabelFor(model => model[0].cstart)</th>
                    <th>@Html.LabelFor(model => model[0].cend)</th>
                    <th>@Html.LabelFor(model => model[0].professor)</th>
                    <th>@Html.LabelFor(model => model[0].units)</th>
                    <th>@Html.CheckBox("test") Select all</th>
                </tr>
                @for (int …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

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

为什么有些开发人员使用'http'和'express'来创建服务器?

特别是在这行代码上:

我是node.js的新手,我见过的大部分教程都是通过初始化服务器的

var http = require('http');
var express = require('express');

app = express();

//omit

http.createServer(app).listen(1337)
Run Code Online (Sandbox Code Playgroud)

其中,如果您已经使用过,express那么您可以这样做:

var express = require('express');
var app = express();

// omit

app.listen(1337,function(){

});
Run Code Online (Sandbox Code Playgroud)

这两个代码结构之间有什么主要区别吗?

node.js express

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

访问shared_ptr数组

#include <memory>

int main()
{
   std::shared_ptr<double> array (new double [256], [](double * d){
      delete [] d;
   });
}
Run Code Online (Sandbox Code Playgroud)

shared_ptr指出了一系列具有自己的自定义删除器的双打.

现在我该如何访问阵列?假设我希望在索引处访问数组1.我尝试了通常的"支架方法",但我得到了错误.

array默认情况下,该词指向其第一个元素,但如果我想访问第二个元素该怎么办?使用增量和括号给我"操作员不匹配"错误.

有人可以向我解释一下发生了什么事吗?

我问这个用于研究目的,尽管意识到unique_ptr并且vector会做得更好.

c++

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

在jquery ajax上使用history.pushstate

我有一个基于ajax的应用程序,其中我只有一个登录页面和主页面.

我的大部分链接都是"ajaxed"我和我这样做:

//get the href of the link that has been clicked, ajaxify ANY links

$(document).on('click', '.tree a', function () {

            var link = $(this).attr('href');  //get the href off the list
            $.ajax({                          //ajax request to post the partial View
                url: link,
                type: 'POST',
                cache: false,
                success: function (result) {
                    $('#target').html(result);
                    $.validator.unobtrusive.parse($("form#ValidateForm"));
                }
            });
            return false; //intercept the link
   });
Run Code Online (Sandbox Code Playgroud)

我想在我的应用程序上实现"pushState",我到目前为止所做的第一步是添加以下代码:

$(document).on('click', 'a', function () {
            history.pushState({}, '', $(this).attr("href"));
 });
Run Code Online (Sandbox Code Playgroud)

现在,每当我点击任何链接并成功加载ajax内容时,它都会更新我的地址栏.我是这个API的新手,所以我不知道我错过了什么,但到目前为止我的问题是:

  1. 当我按下"后退"按钮时,没有任何反应.我读到了关于"popstate"并浏览了SO以寻找解决方案,但我似乎无法让它们发挥作用.

  2. 当我点击历史记录中的链接时,我从主html获得了没有布局的子html的"原始"视图.如果我希望它显示为从我的主应用程序中点击它,我需要做什么?

我的大多数孩子观点都是表格或列表.

javascript ajax jquery

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

访问私有std :: string继承上的字符串

我在书中看到了这个例子:

class Test: private std::string
{
public:
    Test():std::string("How?")
    {
    }
};

int main(int argc, char** argv)
{
    Test t;

    std::cout<<(std::string&)t<<std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我不知道当我对类名称进行类型化时它是如何打印"如何"的?是因为运营商?但我知道,当你进行私有继承时,公共和受保护的变量和方法将被视为"私有".

所以我的问题是,它是如何打印"如何"?

编辑:

那么谁持有字符串值"如何"以及它是如何打印的?因为它是通过类型转换打印的.

c++

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

如何在模型类上添加与数据库无关的属性?

所以我有这个模型类:

[Table("items")]
public class items
{
        public int id { get; set; }
        public string text { get; set; }
        public string value { get; set; }
   //   public int test { get; set; } crashes
}
Run Code Online (Sandbox Code Playgroud)

我使用实体框架。我的桌子有id,text,valuetest财产不属于其中。DbSet我像这样填充我的

public DbSet<items> items { get; set; }

奇怪的是,如果我添加类似的东西,它不会崩溃public List<string> test { get; set; }

我应该怎么办?我本来想添加一个bool?属性。

编辑:我正在考虑创建一个将继承模型的新类,但我必须重新映射/重新填充它。

c# entity-framework asp.net-mvc-4

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

溢出:隐藏在div标签上影响背景颜色

国家的定义overflow:hidden:

the overflowing content is completely hidden, not accessible to the user.

来自:http://quirksmode.org/css/css2/overflow.html

但我对我的js小提琴这种行为感到好奇:https: //jsfiddle.net/gd62qmr3/2/

我注意到的一件事是,在将溢出设置为隐藏后,它为边距赋予了颜色?

<div style="background-color:green;overflow:hidden;">
<p>test</p>
</div>
Run Code Online (Sandbox Code Playgroud)

我想知道为什么会出现这种行为?如果没有溢出,精确的块元素将具有绿色背景颜色,但是溢出将为其边缘提供背景颜色.

html css css3

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