Home Dashboard Directory Help
Search

Can not get size of static array defined in class template by sbauer23


Status: 

Closed
 as Deferred Help for as Deferred


2
0
Sign in
to vote
Type: Bug
ID: 759407
Opened: 8/24/2012 7:48:32 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

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;
}



Details
Sign in to post a comment.
Posted by brettbjackson on 7/3/2014 at 2:46 PM
Any ETA on this will be fixed??
Posted by Microsoft on 8/26/2012 at 7:15 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 8/24/2012 at 7:53 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.