Inherit from Intrinsic

J

JKop

First attempt:

class Blah : public int
{

};



So I began working on the next best thing:


class Blah : public IntrinsicClone<int>
{

};



And here she is:



template<class T> class IntrinsicClone
{
private:

T data;

public:


IntrinsicClone() {}

template<class R> IntrinsicClone(const R r) : data(r) { }

template<class R> T& operator=(const R r) { return data = r; }
template<class R> T& operator+=(const R r) { return data += r; }
template<class R> T& operator-=(const R r) { return data -= r; }
template<class R> T& operator*=(const R r) { return data *= r; }
template<class R> T& operator/=(const R r) { return data /= r; }
template<class R> T& operator%=(const R r) { return data %= r; }
template<class R> T& operator^=(const R r) { return data ^= r; }
template<class R> T& operator&=(const R r) { return data &= r; }
template<class R> T& operator|=(const R r) { return data |= r; }
template<class R> T& operator<<=(const R r) { return data <<= r; }
template<class R> T& operator>>=(const R r) { return data >>= r; }
template<class R> T& operator<=(const R r) { return data <= r; }
template<class R> T& operator>=(const R r) { return data >= r; }

T& operator++() { return ++data; }
T operator++(int) { return data++; }
T& operator--() { return --data; }
T operator--(int) { return data--; }


//And last but not least!
operator T()
{
return data;
}

};



Comments, questions, suggestions.


-JKop
 
J

JKop

I've been playing with the following but can't quite seem
to get it to work. I need to make all the default operators
private.


template<class T> class IntrinsicClone
{
private:

IntrinsicClone();
IntrinsicClone(const IntrinsicClone&);
IntrinsicClone& operator=(const IntrinsicClone&);
IntrinsicClone* operator&();



public:

T data;

operator T&()
{
return data;
}

};




int main()
{
IntrinsicClone<unsigned long> k;

k = 42.5;

}



Anyone shed any light?

-JKop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top