Page 1 of 1

STL

Posted: 23 Apr 2017, 22:49
by david_stelian
Sunt incepator in STL.
In urmatorul cod primesc eroarea ptr was not declared in this scope.
Nu stiu de ce, codul este corect din puctul meu de vedere.

Code: Select all

#include <iostream>
using namespace std;

template <class T>
class Valoare
{
private:
    T *ptr;
public:
    Valoare(T *ptr);
    char *getString();
};

template <class T>
Valoare<T>::Valoare(T *ptr)
{
    this->ptr = new T;
    this->ptr = ptr;
}

template <class T>
char Valoare<T>::*getString()
{
    return ptr;
}

int main()
{
    Valoare<char> obj("Object Oriented Programming");
    cout << "\n " << obj.getString() << endl;

    return 0;
}

Re: STL

Posted: 24 Apr 2017, 21:20
by Viorel
Încearcă următoarea modificare:

Code: Select all

template <class T>
char * Valoare<T>::getString()
{
    return ptr;
}

Re: STL

Posted: 25 Apr 2017, 09:23
by david_stelian
Da, merge.
Multumesc!