Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multi-Parameter Template Class Array problem...............

Started by Leiarchy9 Jan 29, 2004 at 3:32 PM 0 replies 300+ views
Original Post
Leiarchy9
Leiarchy9
All is going well code-wise apparently. No compiler errors..........it outputs all of the numbers onto the screen properly. But there is no big problem. At the end of the program.....(in Windows XP) I get a pop-up dialog box that tells me that the application I''m running has a problem. Here is the code. ~Source
#include <iostream>
#include <cstdlib>

#include "Main.h"

   using std::cout;
   using std::cin;

   
   
int main(void)
{

     CArray<int, 20, 0> array;
     
     SetRandom( array );
     PrintArray( array );
     

     cin.get();
     return EXIT_SUCCESS;
}


void SetRandom( CArray<int, 20, 0> pArray )
{

     srand( (int)time(0) );
     
     for( int i = 0; i < pArray.Size(); i++ )
     {
     
        pArray.SetElement( i, rand() % 50 );
     }
     
}


void PrintArray( CArray<int, 20, 0> array )
{

     for( int i = 0; i < array.Size(); i++ )
     {
     
        cout << array.GetElement( i ) << ", ";
     }
     
}
~Header File
#ifndef _Main_h
#define _Main_h



template<class dataType, int size, dataType zero>
class CArray
{

     dataType * _array;
     
     public:

        CArray(void) { }
        
        void SetElement( int index, dataType value )
        {
        
           _array[index] = value;
        }
        
        void ClearElement( int index )
        {
        
           _array[index] = zero;
        }
        
        dataType GetElement( int index )
        {
        
           return( _array[index] );
        }
        
        int Size(void) const
        {
        
           return size;
        }
        
};


void SetRandom(CArray<int, 20, 0>);

void PrintArray(CArray<int, 20, 0>);


#endif
-------- "Do you believe in Ghost?"
--------"Do you believe in Ghost?"
SiCrane
SiCrane
When do you initialize the _array pointer? Do you ever initialize the _array pointer?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.