Clase Template

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
stelian_2681
Junior
Junior
Posts: 36
Joined: 24 Jun 2013, 23:25
Judet: Olt

Clase Template

Post by stelian_2681 » 01 May 2017, 12:55

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;
}



Viorel
Microsoft MVP
Microsoft MVP
Posts: 286
Joined: 13 Jul 2007, 12:26

Re: Clase Template

Post by Viorel » 01 May 2017, 19:29

Mai adaugă un 't': FirstClass.

stelian_2681
Junior
Junior
Posts: 36
Joined: 24 Jun 2013, 23:25
Judet: Olt

Re: Clase Template

Post by stelian_2681 » 01 May 2017, 20:13

Da, ai dreptate nu am vazut.
Multumesc.

Post Reply