小编use*_*915的帖子

不允许使用C++数据成员初始值设定项

我对C++很陌生,所以请耐心等待.我想用静态数组创建一个类,并从main访问这个数组.这是我想用C#做的事情.

   namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Class a = new Class();
                Console.WriteLine(a.arr[1]);

            }
        }
    }

    =====================

    namespace ConsoleApplication1
    {
        class Class
        {       
            public static string[] s_strHands = new string[]{"one","two","three"};
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

// justfoolin.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

class Class {

  public:
      static string arr[3] = {"one", "two", "three"};
};


int _tmain(int argc, _TCHAR* argv[])
{
    Class x;
    cout …
Run Code Online (Sandbox Code Playgroud)

c++ arrays

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

C++数组转移到元素

好吧标题不是最好的,但这是我正在寻找的.

int arr[] = {3, 4, 5, 6, 7};
int index = 2;
someFunctionICantRemember(int arr, int index);

// result {5, 6, 7, 3, 4}
Run Code Online (Sandbox Code Playgroud)

我在www.cplusplus.com上看到了这个功能,但我再也找不到了.据我所知,它是"内置的".

c++ arrays shift

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

标签 统计

arrays ×2

c++ ×2

shift ×1