配列テンプレートをテストしています。文字列型とintに対しては正常に機能しますが、typedefStudentに対しては機能しません。理解しようとしましたが、問題が見つかりません。単なるテストであるため、個別のコンパイルは使用しませんでした。Dev-C++を使用しています。あなたの助けは非常に高く評価されます。コードは以下のとおりです。
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
class Array
{
public:
Array(int initialSize);
~Array();
T & operator[](int i);
private:
T * m_pData;
int m_nSize;
};
//Implementing member functions in the Array template
template <typename T>
Array <T>::Array(int initialSize)
{
m_nSize = initialSize;
m_pData = new T [m_nSize];
};
template <typename T>
T & Array <T>::operator[](int i)
{
return m_pData[i];
};
template <typename T>
Array <T>::~Array()
{
delete[] m_pData;
};
typedef struct Student{}students[0];
//test array class implementatition
int main()
{
//creating an array of 20 integers, then assigning the value 50 at index 2
Array <int> myArray (20);
myArray[2] = 50;
cout << myArray[2] <<endl;
//creating an array of string of size 10, then assigning the string "Fred" at index 5
//then display the string
Array <string> nameArray (10);
nameArray[5] = string("Fred");
cout << nameArray[5] <<endl;
//creating an array of Student of size 100, then assigning the value "123456789" at index 4
//then display the value at that index
Array <Student> students (100);
students[4] = Student("123456789"); //here is the problem!!!
///cout << students[4] <<endl;
system ("pause");
return 0;
}