


Just curious why the following does not work under Visual Studio (it does under gcc). // ConsoleApplication1.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> // *********************************************************** /** Macro to count the number of items in an array */ #define m_COUNT1(x) (sizeof(x)/sizeof(x[0])) // *********************************************************** template<typename T, std::size_t size> std::size_t GetArrLength(T(&)[size]) { return size; } #define m_COUNT2(pArray) GetArrLength(pArray) // *********************************************************** template <typename T> class TempClass { public: static int tempclass_array[]; static int tempclass_array_count1_size; static int tempclass_array_count2_size; }; template <typename T> int TempClass<T>::tempclass_array[] = { 1, 2, 3, 4, }; template <typename T> int TempClass<T>::tempclass_array_count1_size = m_COUNT1(TempClass<T>::tempclass_array); template <typename T> int TempClass<T>::tempclass_array_count2_size = m_COUNT2(TempClass<T>::tempclass_array); class ImplClass : public TempClass<ImplClass> { public: static int implclass_array[]; static int implclass_array_count1_size; static int implclass_array_count2_size; }; int ImplClass::implclass_array[] = { 1, 2, 3, 4, }; int ImplClass::implclass_array_count1_size = m_COUNT1(ImplClass::implclass_array); int ImplClass::implclass_array_count2_size = m_COUNT2(ImplClass::implclass_array); int _tmain(int argc, _TCHAR* argv[]) { std::cout << "size of tempclass_array is " << ImplClass::tempclass_array_count1_size << std::endl; std::cout << "size of tempclass_array is " << ImplClass::tempclass_array_count2_size << std::endl; std::cout << "size of implclass_array is " << ImplClass::implclass_array_count1_size << std::endl; std::cout << "size of implclass_array is " << ImplClass::implclass_array_count2_size << std::endl; return 0; }