小编Fel*_*elB的帖子

为什么在这个例子中调用了复制构造函数?

我是C++的新手,我不明白为什么在下面的代码中调用了复制构造函数:

 #include <iostream>

    using namespace std;

    class Line

{
   public:
      int getLength( void );
      Line( int len );             // simple constructor
      Line( const Line &obj);  // copy constructor
      ~Line();                     // destructor

   private:
      int *ptr;
};

// Member functions definitions including constructor
Line::Line(int len)
{
    cout << "Normal constructor allocating ptr" << endl;
    // allocate memory for the pointer;
    ptr = new int;
    *ptr = len;
}

Line::Line(const Line &obj)
{
    cout << "Copy constructor allocating ptr." << endl;
    ptr = …
Run Code Online (Sandbox Code Playgroud)

c++ constructor

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

根据其他列的值填充pandas列的简便方法

我有一个包含3列的pandas DataFrame,如下所示:

      a   b   c
0      1  1  10
1     2  12  10
2    16  13  10
3      9 16  10
Run Code Online (Sandbox Code Playgroud)

在第一列中,c我希望每行中最多有3个数字,所以它应该如下所示:

      a   b   c
0      1  1  10
1     2  12  12
2    16  13  16
3      9 16  16
Run Code Online (Sandbox Code Playgroud)

我可以用for循环做这个,但我想知道是否有更简单的方法来做到这一点?

python dataframe pandas

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

什么是"int*a [] [10];"?

问题在于标题:

什么是 int * a[][10];

它是一个指向int数组的指针数组吗?我试着顺时针/螺旋规则,但我不确定......

c++ arrays pointers

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

C++中string.size()的类型是什么?

我有以下代码:

#include<iostream>
#include<string>   
int main()
    {
        std::string s = "458";
        std::cout <<s.size()-4;
    }
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我得到42944935或类似的东西.但是当我通过以下修改运行它时:

int main()
{
    std::string s = "458";
    int i = s.size();
    std::cout << i -4;
}
Run Code Online (Sandbox Code Playgroud)

我得到-1,这是我从第一个代码中得到的.有人能解释一下这里发生了什么吗?

c++ string

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

标签 统计

c++ ×3

arrays ×1

constructor ×1

dataframe ×1

pandas ×1

pointers ×1

python ×1

string ×1