Page 1 of 1

Clase Template

Posted: 01 May 2017, 12:55
by stelian_2681
In codul urmator am 2 erori, codul este scris corect si nu inteleg de ce primesc aceste erori.

|14|error: 'FirsClass' does not name a type|
|20|error: expected initializer before '<' token|

Code: Select all

#include <iostream>
using namespace std;

template <class T>
class FirstClass
{
private:
    T x;
public:
    FirstClass(T x);
    void setX(T x);
    T getX();
};
template <class T> FirsClass<T>::FirstClass(T x)
{
    cout << "\n Apel constructor cu parametri(FirstClass)" << endl;
    this->x = x;
    cout << "\n x = " << x << endl;
}
template <class T> void FirsClass<T>::setX(T x)
{
    this->x = x;
}
template <class T> T FirstClass<T>::getX()
{
    return x;
}

int main()
{
    FirstClass<int> obj1(300);
    obj1.setX(500);
    cout << "\n x = " << obj1.getX() << endl;
    return 0;
}

Re: Clase Template

Posted: 01 May 2017, 19:29
by Viorel
Mai adaugă un 't': FirstClass.

Re: Clase Template

Posted: 01 May 2017, 20:13
by stelian_2681
Da, ai dreptate nu am vazut.
Multumesc.