小编use*_*905的帖子

构造函数哪种方式最好?

构造类有两种方法:

  class Cell{
  public:
        Cell(int cellID, int nx);
        ~Cell();
  private:
        int cellID_;
        int nx;
  };
Run Code Online (Sandbox Code Playgroud)

第一种方式:

  Cell::Cell(int cellID, int nx)
    : cellID_(cellID), nx_(nx){}
Run Code Online (Sandbox Code Playgroud)

第二种方式:

  Cell::Cell(int cellID, int nx){init(cellID, nx)}

  void Cell::init(int cellID, int nx){
         cellID_ = cellID;
         nx_ = nx;
  }
Run Code Online (Sandbox Code Playgroud)

c++ constructor

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

我无法使用C++编译MPI编译器

我试图编译一个非常简单的MPI hello_world:

#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv[]) {
    int numprocs, rank, namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Get_processor_name(processor_name, &namelen);

    printf("Process %d on %s out of %d\n", rank, processor_name, numprocs);

    MPI_Finalize();
}
Run Code Online (Sandbox Code Playgroud)

并得到以下问题:

    Catastrophic error: could not set locale "" to allow processing of multibyte characters
Run Code Online (Sandbox Code Playgroud)

我真的不知道该怎么弄清楚.

c++ compiler-construction mpi

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

标签 统计

c++ ×2

compiler-construction ×1

constructor ×1

mpi ×1