STL

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
david_stelian
Junior
Junior
Posts: 17
Joined: 13 Sep 2014, 22:35
Judet: Dolj

STL

Post by david_stelian » 23 Apr 2017, 22:49

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



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

Re: STL

Post by Viorel » 24 Apr 2017, 21:20

Încearcă următoarea modificare:

Code: Select all

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

david_stelian
Junior
Junior
Posts: 17
Joined: 13 Sep 2014, 22:35
Judet: Dolj

Re: STL

Post by david_stelian » 25 Apr 2017, 09:23

Da, merge.
Multumesc!

Post Reply