i'm build a completed new code for properties:
#include <iostream>
#include <functional>
using namespace std;
template <typename T>
class property
{
private:
T PropertyValue;
//i think these is ok, but something seems not
std::function<T(void)> getf;
std::function<void(T)> setf;
public:
property()
{
getf=NULL;
setf=NULL;
};
property(T value)
{
PropertyValue=value;
};
property(std::function<void(void)> GetFunction=NULL,std::function<T(void)> SetFunction=NULL)// what isn't right here?
{
setf=SetFunction;
getf=GetFunction;
}
property& operator=(T value)
{
if(getf==NULL || setf==NULL)
PropertyValue=value;
else
setf(value);
return *this;
}
T& operator=(property value)
{
if(getf==NULL || setf==NULL)
return PropertyValue;
else
return getf();
}
friend ostream& operator<<(ostream& os, const property& dt)
{
if(getf==NULL && setf==NULL) //error these don't make sence to me :(
os << dt.PropertyValue;
else if (getf!=NULL)
os << getf();
else
return 0;
return os;
}
friend istream& operator>>(istream &input,property &dt)
{
if(getf==NULL && setf==NULL) //error these don't make sence to me :(
input << dt.PropertyValue;
else if (setf!=NULL)
input << setf();
else
return 0;
return input;
}
};
class test
{
private:
int age;
int getage()
{
return age;
}
void setage(int value)
{
age=value;
}
public:
test()
{
//nothing
}
property<string> Name;
property<int> Age(&getage,&setage); //error
};
test a;
int main()
{
a.Name="joaquim " "Miguel";
a.Age=10+15;
cout << a.Age << endl;
cout << "what is your name?\n";
cin >> a.Age;
cout << "your name is: " << a.Age << endl;
return 0;
}
but i get 23 errors, if is need, i can give all the info.
sorry, but i'm not getting help :(
please someone tell me something