V
Vespasian
I get the following compilation errors,
error C2057: expected constant expression
error C2133: 'tempArray' : unknown size
error C2466: cannot allocate an array of constant size 0
when compiling the following code:
template<class X> class Array {
public:
Array(int s) {size = s; }
int get_size(void) { return size; }
private:
int size;
};
#include <iostream>
#include <string>
#include "temp.h"
using namespace std;
template<class X> void Merge (Array<X>& values)
{
X tempArray[values.get_size()];
}
int main() {
int num;
cout << "How many words? ";
cin >> num;
Array<string> b(num);
Merge(b);
return 0;
}
Not sure why the errors occur. How do I fix this problem?
TIA,
ves
error C2057: expected constant expression
error C2133: 'tempArray' : unknown size
error C2466: cannot allocate an array of constant size 0
when compiling the following code:
template<class X> class Array {
public:
Array(int s) {size = s; }
int get_size(void) { return size; }
private:
int size;
};
#include <iostream>
#include <string>
#include "temp.h"
using namespace std;
template<class X> void Merge (Array<X>& values)
{
X tempArray[values.get_size()];
}
int main() {
int num;
cout << "How many words? ";
cin >> num;
Array<string> b(num);
Merge(b);
return 0;
}
Not sure why the errors occur. How do I fix this problem?
TIA,
ves