C#:
public class ConstTest
{
public int Age;
public ConstTest(int TheAge)
{
this.Age = TheAge;
}
}
public class TheTest
{
public static readonly ConstTest theTest = new ConstTest(5);
}
class CryptoMemoryStream
{
public static void Main()
{
Console.WriteLine(TheTest.theTest.Age);
}
}
C++:
#pragma once
#include "stdafx.h"
using namespace std;
class ConstTest
{
public:
int Age ;
ConstTest::ConstTest(int TheAge) ;
};
ConstTest::ConstTest(int TheAge)
{
Age = TheAge ;
}
class TheTest
{
public :
static const ConstTest theTest ;
TheTest::TheTest() ;
};
const ConstTest TheTest::theTest = ConstTest(5) ;
int _tmain(int argc, _TCHAR* argv[])
{
std::cout<< TheTest::theTest.Age ;
return 0;
}
请SW跟贴。