আমি যখন floatটেমপ্লেট প্যারামিটার হিসাবে ব্যবহার করার চেষ্টা করি তখন সংকলকটি এই কোডটির জন্য কাঁদে, যখন intকাজ করে ভাল।
এটি কি কারণ আমি floatটেমপ্লেট প্যারামিটার হিসাবে ব্যবহার করতে পারি না ?
#include<iostream>
using namespace std;
template <class T, T defaultValue>
class GenericClass
{
private:
T value;
public:
GenericClass()
{
value = defaultValue;
}
T returnVal()
{
return value;
}
};
int main()
{
GenericClass <int, 10> gcInteger;
GenericClass < float, 4.6f> gcFlaot;
cout << "\n sum of integer is "<<gcInteger.returnVal();
cout << "\n sum of float is "<<gcFlaot.returnVal();
return 0;
}
ত্রুটি:
main.cpp: In function `int main()':
main.cpp:25: error: `float' is not a valid type for a template constant parameter
main.cpp:25: error: invalid type in declaration before ';' token
main.cpp:28: error: request for member `returnVal' in `gcFlaot',
which is of non-class type `int'
আমি রন পেন্টনের "গেম প্রোগ্রামার্সের জন্য ডেটা স্ট্রাকচারস" পড়ছি , লেখক পাস করেছেন float, তবে আমি যখন চেষ্টা করে দেখি তখন এটি সংকলিত হয় না।
floatএকটি নন-টাইপ টেম্পলেট প্যারামিটার হিসাবে ব্যবহার করেন ? কোন অধ্যায়ে এটি?