I have the following class setup that trys mimicks a very basic stack.
template <class T>
class Stack{
public:
static const unsigned MAX_STACK_DEPTH =4;
Stack();
unsigned elements() const;
Stack<T> & push(T &value);
T pop();
Stack<T> & show();
private:
unsigned element;
T stack[MAX_STACK_DEPTH];
};
template <class T>
Stack<T>::Stack(){
element=0;
}
/*Other class function definitions*/
My problem is that I’m getting the following error in main
1 IntelliSense: no instance of function template "calc" matches the argument list c:\users\nima\documents\visual studio 2010\projects\calcu\calcu\policalc.cpp 109 6 Calcu
Here is my main
int main(){
bool run=true;
while(run){
if(calc(input()));
}
}
here are the other two functions declarations
string input();
template <class T>
bool calc(string line);
Here is my calc function, It’s not finished.
template <class T>
bool calc(string line){
static T Ans;
istringstream sin(line);
Stack stack;
for(string token; sin>>token){
T t;
if(parse(t, token)){
push(t);
}else{
if(token==operators[i]){
switch(i){
case 1:{
}
}
}
}
}
}
Your
calcfunction is a function template with parameterT, but that parameter isn’t used by any of the function arguments – the only argument is defined as astring, regardless of what typeTis.Therefore, the compiler cannot defer
Twhen you callcalclike this:You need to explicitly specify
T, e.g.:(Of course, you should use whatever data type makes sense instead of
int.)