小编Dev*_*wal的帖子

为什么sizeof(Derived4)是8字节?我认为它应该是5个字节

这是给定程序的输出:

sizeof(Empty) 1
sizeof(Derived1) 1
sizeof(Derived2) 4
sizeof(Derived3) 1
sizeof(Derived4) 8
sizeof(Dummy) 1
Run Code Online (Sandbox Code Playgroud)

这是该计划:

#include <iostream>
using namespace std;

class Empty
{};

class Derived1 : public Empty
{};

class Derived2 : virtual public Empty
{};

class Derived3 : public Empty
{    
    char c;
};

class Derived4 : virtual public Empty
{
    char c;
};

class Dummy
{
    char c;
};

int main()
{
    cout << "sizeof(Empty) " << sizeof(Empty) << endl;
    cout << "sizeof(Derived1) " << sizeof(Derived1) << endl;
    cout …
Run Code Online (Sandbox Code Playgroud)

c++ sizeof virtual-inheritance memory-layout empty-class

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

为什么将unique_ptr与数组一起使用会导致编译错误?

为什么使用unique_ptr <string> items;而不是原始指针string *items;抛出编译错误.

#include <iostream>
#include <memory>
using namespace std;

class myarray
{
  private:
    unique_ptr <string> items;
    //string *items;
  public:
    myarray (int size=20) : items (new string [size] ) {}

    string& operator[] (const int index)
    {
      return items[index];
    }
};


int main()
{
  myarray m1(200);
  myarray m2;
  m1[19] = "test";
  cout << m1[19];
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:

subscript2.cpp: In member function ‘std::string& myarray::operator[](int)’:
subscript2.cpp:15: error: no match for ‘operator[]’ in ‘((myarray*)this)->myarray::items[index]’
Run Code Online (Sandbox Code Playgroud)

c++ arrays unique-ptr

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

如何在c ++中初始化具有相同值的2D数组

我们可以使用fill_n函数用值初始化1D数组.

int table[20];
fill_n(table, 20, 100);
Run Code Online (Sandbox Code Playgroud)

但是我们如何用相同的值初始化2D数组.

int table[20][20];
fill_n(table, sizeof(table), 100); //this gives error
Run Code Online (Sandbox Code Playgroud)

c++ arrays stl initialization

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

Perl中的"CGI :: param在列表上下文中调用"警告

我有一个在数据库中添加数据的perl脚本

    #!/usr/bin/perl
    use cPanelUserConfig;


    use strict;
    use warnings;
    use DBI;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    use CGI;
    use CGI::Cookie;
    use CGI::Session qw();
    use JSON;
    #use MIME::Lite;

    my $CFG = do "config.pl";
    my $cgi = CGI->new;
    my $db_handle = DBI->connect ("DBI:mysql:$CFG->{database}", $CFG->{user}, $CFG->{password} ) or die "Couldn't connect to database: $DBI::errstr\n";

    my $decdata = decode_json($cgi->param('POSTDATA'));

    my $CustomerID;# = $decdata->{'CustomerID'};
    my $DeliverySlot = $decdata->{'DeliverySlot'};
    my $PaymentMode = $decdata->{'PaymentMode'};
    my $CustomerName = $decdata->{'CustomerName'};
    my $Address = $decdata->{'Address'};
    my $City = $decdata->{'City'};
    my $Mobile = …
Run Code Online (Sandbox Code Playgroud)

perl

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

如何获取pandas中第一行和当前行之间的差异

我在数据框中有 2 列(日期和销售价格)。我的预期输出是这样的。我想在数据框中添加一个名为利润的列,该列需要通过当前的销售价格计算 - 第一个销售价格(星级一)

        date            sell_price  profit(needs to be added)
    0   2018-10-26       **21.20**    NaN
    1   2018-10-29       15.15      -6.05
    2   2018-10-30       15.65      -5.55
    3   2018-10-31        0.15     -21.05
    4   2018-11-01        5.20     -16.00
Run Code Online (Sandbox Code Playgroud)

我知道熊猫中的差异会导致连续行之间的差异。我们如何在 Pandas 上使用 diff 或任何其他函数实现预期的 o/p?

python pandas

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

为什么这个c ++程序的输出是3

#include <iostream>
using namespace std;

int i;

class A
{
public:
    ~A()
    {
        i=10;
    }
};

int foo()
{
    i=3;
    A ob;
    return i;
}

int main()
{
    cout << "i = " << foo() << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出为3,为什么不是10.

c++

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

在angularJS中使用ng-style而不是style时出错

这是我显示类别的代码:

    <select ng-style="margin-left:30px;" ng-show="ShowBrand" ng-model="SelectedBrand" ng-options="x as x.name for x in Brands | orderBy:'name'" ng-class='form-control'>
        <option value="" ng-selected="selected">Select a Brand</option>
    </select>
Run Code Online (Sandbox Code Playgroud)

我在colsole窗口中看到以下错误:

    Error: [$parse:syntax] http://errors.angularjs.org/1.2.16/$parse/syntax?p0=%3A&p1=is%20an%20unexpected%20token&p2=12&p3=margin-left%3A30px%3B&p4=%3A30px%3B
        at Error (native)
        at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:6:450
        at $a.throwError (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:165:141)
        at $a.parse (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:164:6)
        at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:96:122
        at k (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:102:227)
        at h.$watch (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:103:380)
        at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:197:313
        at J (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:53:345)
        at f http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js:46:399

select ng-style="margin-left:30px;" ng-show="ShowBrand" ng-odel="SelectedBrand" ng-options="x as x.name for x in Brands | orderBy:'name'" ng-class="form-control" class="ng-pristine ng-valid">
Run Code Online (Sandbox Code Playgroud)

此错误仅在我使用ng-style时.如果我使用样式而不是ng-style然后无法在IE9上呈现.

这个错误的原因是什么以及如何解决?

html javascript css angularjs

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

如何在 curdate mysql 中添加小时和分钟

我正在使用 date_add 函数在当前日期中添加 12 小时 30 分钟。

 select DATE_ADD( CURDATE( ) , INTERVAL  '12:30' HOUR_MINUTE )
Run Code Online (Sandbox Code Playgroud)

给我 2016-01-03 12:30:00

我只需要添加 12:30 后的日期。

做同样的事情的正确方法是什么?

mysql

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

如何在改造 2.0 的 onResponse 上处理对象

这是我在改造 2.0 中获得响应的逻辑

call.enqueue(new Callback<ArrayList<Wallet>>() {
  @Override
  public void onResponse(Response<ArrayList<Wallet>> response, Retrofit retrofit) {

      if (response.isSuccess()) {
          // use response data and do some fancy stuff :)
         loading.dismiss();
          ArrayList<Wallet> orders = response.body();
          Utility.displayToast("Wallet size is" + orders.size());

      } else {

      }
  }

});


Data format from rest API is like this:

[
{
  "description": "Cashback",
  "amount": "20.00",
  "type": "1",
  "date": "11/03/2016"
},
{
  "description": "CASH BACK",
  "amount": "12.00",
  "type": "1",
  "date": "05/03/2016"
}
]
Run Code Online (Sandbox Code Playgroud)

现在他们改变了 API,数据是这样的:

{
  "error": false,
  "wallet": …
Run Code Online (Sandbox Code Playgroud)

android retrofit2

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

如何在Android中更新菜单项

我有一个菜单项活动。每次用户参加此活动时,我都想用一些Utility值更新textView的值。这是我的代码。

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_my2, menu);
    return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu){
    RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.badge).getActionView();
    TextView tv = (TextView) badgeLayout.findViewById(R.id.actionbar_notifcation_textview);
    tv.setText(String.valueOf(Utility.ShoppingCartItemCount()));
    return true;
}
Run Code Online (Sandbox Code Playgroud)

这仅一次更新值(启动活动时)。但是,当用户从该活动中移出并再次进行此活动时,即使Utility.ShoppingCartItemCount()的值也没有更新。

如何解决呢?

android

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