我对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) 好吧标题不是最好的,但这是我正在寻找的.
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上看到了这个功能,但我再也找不到了.据我所知,它是"内置的".