T
Tony Johansson
Hello Experts!
Why do I get compile error here in this small class template. The compiler
error give this error
c:\Documents and Settings\Tony\kau\cplusplus\test12\start.cpp(9): error
C2440: '=' : cannot convert from 'int *' to 'int'
It's something that I have forgot in the class template..
#include <iostream>
template<typename T, int size>
class Array
{
public:
const int& operator[](int pos) const { return value[pos]; }
int& operator[](int pos) { return value[pos]; }
private:
T value[size];
};
#include <iostream>
#include "array.h"
using namespace std;
int main()
{
Array<int*,1> array1, array2;
array1[0] = new int(3);
return 0;
}
Many thanks
//Tony
Why do I get compile error here in this small class template. The compiler
error give this error
c:\Documents and Settings\Tony\kau\cplusplus\test12\start.cpp(9): error
C2440: '=' : cannot convert from 'int *' to 'int'
It's something that I have forgot in the class template..
#include <iostream>
template<typename T, int size>
class Array
{
public:
const int& operator[](int pos) const { return value[pos]; }
int& operator[](int pos) { return value[pos]; }
private:
T value[size];
};
#include <iostream>
#include "array.h"
using namespace std;
int main()
{
Array<int*,1> array1, array2;
array1[0] = new int(3);
return 0;
}
Many thanks
//Tony