I have three files: main:
#include <iostream>
#include "Punkt.h"
int main() {
const Punkt s1(0, 1);
const Punkt s2(-5, 2);
std::cout << "s1 " << s1.wsp<0>() << " " << s1.wsp<1>() << std::endl;
}
header:
#include <iostream>
#pragma once
class Punkt{
public:
Punkt(int x, int y){
m_x = x;
m_y = y;
}
template <typename T> int wsp() const;
private:
int m_x;
int m_y;
};
cpp:
#include "Punkt.h"
#include <iostream>
using namespace std;
template <typename T>
int Punkt::wsp() const
{
int obiekt(T);
try{
if (obiekt==1){
return m_y;
}
if (obiekt==0){
return m_x;
}
throw;
}
catch(...){
std::cout << "Incorrect number" << std::endl;
}
}
and the problem:
Main.cpp:46:35: error: no matching function for call to ‘Punkt::wsp() const’
std::cout << "s1 " << s1.wsp<0>() << " " << s1.wsp<1>() << std::endl;
In file included from Main.cpp:39:0:
Punkt.h:11:28: note: candidate: template<class T> int Punkt::wsp() const
template <typename T> int wsp() const;
Punkt.h:11:28: note: template argument deduction/substitution failed:
I am starting with templates and I don't understand what is going on. When I change wsp to: 'template '(and the fuction ofc) it works fine. Do someone have any idea?