我完全不熟悉C++,所以忍耐着我。我想用靜態數組創建一個類,並從main訪問這個數組。這是我想要在C#中完成的任務。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"};
}
}
這裏是我曾嘗試:
// 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 << x.arr[2] << endl;
return 0;
}
但我得到: 智能感知:數據成員初始化不允許
沒有我gusta'使用namespace std;' –