473,467 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Template class problem

1 New Member
Hi!



I am new in Visual C++ and now I face with a problem.



I have the below code written into a header file. At compile time I get the following error:



error C2248: 'CRCTable' : cannot access private struct declared in class 'CRCHash<unsigned long,-306674912,-1,-1>'

see declaration of 'CRCTable'

while compiling class-template static data member 'const struct CRCHash<unsigned long,-306674912,-1,-1>::CRCTable CRCHash<unsigned long,-306674912,-1,-1>::Table'



What shoul I do to get rid of this error?

Thanks in advance!





Expand|Select|Wrap|Line Numbers
  1. #ifndef CRCHashH
  2. #define CRCHashH
  3.  
  4. //******************************************************************************
  5. // Template class 'CRCHash' implements mirror-algorithm of CRC calculation.
  6.  
  7. template <typename T, const T POLYNOM, const T INITIAL, const T FINAL>
  8. class CRCHash
  9.     {
  10.     private:
  11.         T CRC;
  12.         struct CRCTable { T Data[256]; CRCTable(void); };
  13.         static const CRCTable Table;
  14.     public:
  15.         CRCHash(void) : CRC(INITIAL) {;};
  16.         CRCHash(const CRCHash & iCRCHash) : CRC(iCRCHash.CRC) {;};
  17.         void Reset(void) { CRC = INITIAL; };
  18.         void Update(const void *Buffer, size_t Length);
  19.         inline void Update(unsigned char Value);
  20.         T Evaluate(void) const { return CRC ^ FINAL; };
  21.         static T Evaluate(const void *Buffer, size_t Length);
  22.     };
  23.  
  24. template <typename T, T POLYNOM, T INITIAL, T FINAL>
  25.     const CRCHash<T, POLYNOM, INITIAL, FINAL>::CRCTable
  26.         CRCHash<T, POLYNOM, INITIAL, FINAL>::Table;
  27.  
  28. //******************************************************************************
  29.  
  30.  
  31. template <typename T, T POLYNOM, T INITIAL, T FINAL>
  32.     CRCHash<T, POLYNOM, INITIAL, FINAL>::
  33.         CRCTable::CRCTable(void)
  34.             {
  35.             for (int i = 0, t = 0; i < 256; t = 8, i++)
  36.                 {
  37.                 Data[i] = i;
  38.                 while (t--) Data[i] = Data[i] >> 1 ^ (Data[i] & 1 ? POLYNOM :0);
  39.                 }
  40.             }
  41.  
  42. //******************************************************************************
  43.  
  44. template <typename T, T POLYNOM, T INITIAL, T FINAL>
  45.     void CRCHash<T, POLYNOM, INITIAL, FINAL>::
  46.         Update(unsigned char Value)
  47.             {
  48.             CRC = CRC >> 8 ^ Table.Data[Value ^ CRC & 0xFFU];
  49.             }
  50.  
  51. //******************************************************************************
  52.  
  53. template <typename T, T POLYNOM, T INITIAL, T FINAL>
  54.     void CRCHash<T, POLYNOM, INITIAL, FINAL>::
  55.         Update(const void *Buffer, size_t Length)
  56.            {
  57.            register const unsigned char * Block =
  58.                static_cast<const unsigned char *>(Buffer);
  59.            while (Length--) Update(*Block++);
  60.            }
  61.  
  62. //******************************************************************************
  63.  
  64. template <typename T, T POLYNOM, T INITIAL, T FINAL>
  65.     T CRCHash<T, POLYNOM, INITIAL, FINAL>::
  66.         Evaluate(const void *Buffer, size_t Length)
  67.             {
  68.             CRCHash Instance;
  69.             Instance.Update(Buffer, Length);
  70.             return Instance.Evaluate();
  71.             }
  72.  
  73. //******************************************************************************
  74.  
  75. typedef unsigned char  CRC08;
  76. typedef unsigned short CRC16;
  77. typedef unsigned long  CRC32;
  78.  
  79. class CRC08Hash : public CRCHash<CRC08, 0x8CU, 0xFFU, 0xFFU> {};
  80. class CRC16Hash : public CRCHash<CRC16, 0xA001U, 0x0000U, 0x0000U> {};
  81. class CRC32Hash : public CRCHash<CRC32, 0xEDB88320UL, 0xFFFFFFFFUL, 0xFFFFFFFFUL> {};
  82.  
  83. //******************************************************************************
  84.  
  85. // typedef unsigned __int64 CRC64;
  86. // class CRC64Hash : public CRCHash<CRC64, 0x000000000000001BUI64, 0xFFFFFFFFFFFFFFFFUI64, 0xFFFFFFFFFFFFFFFFUI64> {};
  87.  
  88. //******************************************************************************
  89.  
  90. #endif
Jan 7 '08 #1
1 1696
Savage
1,764 Recognized Expert Top Contributor
This compiles in Borland C++ builder..but in VC++(although I didn't tested,I sawed this from your post) it doesn't,it's whining about that static member of yours,Table when it reaches:

Expand|Select|Wrap|Line Numbers
  1.  class CRC32Hash : public CRCHash<CRC32, 0xEDB88320UL, 0xFFFFFFFFUL, 0xFFFFFFFFUL> {};
I wanted to ask you for what purposes do you need that member to be static?
Have you tried compiling without static keyword at Table definition?

Savage
Jan 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Patrick Kowalzick | last post by:
Dear all, I have a question about default template parameters. I want to have a second template parameter which as a default parameter, but depends on the first one (see below). Is something...
4
by: Sebastian Faust | last post by:
Hi, I have 4 questions related to templates. I wanna do something like the following: template<typename T> class Template { public: Template_Test<T>()
6
by: Adam Parkin | last post by:
Hello, all I'm having a problem with friend functions in a templatized Queue class I'm writing using linked lists. The problem is that I can't get the friend function to be able to access private...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
0
by: Leslaw Bieniasz | last post by:
Cracow, 16.09.2004 Hi, I have a problem with compiling the following construction involving cross-calls of class template methods, with additional inheritance. I want to have three class...
2
by: Siegfried Weiss | last post by:
Hi guys, i give up finding a solution by reading or by trial & error. Hope, YOU can help me! (Sorry for my rather long posting.) Stroustrup says, that templates could be declared with - type...
3
by: Chris | last post by:
I am having a very strange problem involving virtual functions in template classes. First of all, here is an extremely simplified structure of the two classes I am having problems with. ...
19
by: aaragon | last post by:
Hi everyone. A very simple question. I would like to know what is better in terms of performance. I want to use a simple function to obtain the minimum of two values. One way could be using a...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
4
by: danilo.turina | last post by:
Hi all, today I encountered a problem that I'm only able to solve by using reinterpret_cast (and I'd like to avoid it). This was my code until yesterday (omitting includes, "using namespace"...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.