Eugen Funk:
AccessResult getAt(idx i) const;
If it is a method, what is the return type?
And what is (idx i)? Is it 2 arguments or is idx a data type?
This is compiling without error:
template <typename T> class RingBuffer { public: class AccessResult { public: bool valid; T item; }; AccessResult getAt(int i) const; }; void f() { RingBuffer<int>::AccessResult res; }
I modified your version so that it can return a pointer:
template <typename T> class RingBuffer { public: class AccessResult { public: bool valid; T item; }; static AccessResult* getAt(int) { return(NULL); } }; void OnStart() { RingBuffer<int>::AccessResult *res = RingBuffer<int>::getAt(123); }
It looks like I was able to make a copy of the object using the auto pointer while doing so.
But to be honest, I've never used template before😄 This is my first experience with template.
template <typename T> class RingBuffer{ public: class AccessResult { public: bool valid; T item; AccessResult() { Print(__FUNCSIG__, " ", EnumToString(CheckPointer(GetPointer(this)))); } AccessResult(AccessResult& a) { valid = a.valid; item = a.item; Print(__FUNCSIG__, " ", EnumToString(CheckPointer(GetPointer(this)))); } }; AccessResult* someInstance; AccessResult* getInstance() { return(someInstance); } RingBuffer() { someInstance = new AccessResult; } ~RingBuffer() { delete someInstance; } }; void OnStart() { RingBuffer<int> buffer; RingBuffer<int>::AccessResult objectCopy(buffer.getInstance()); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I would like to have the following structure:
With this, I can declare a RingBuffer like this:
and then access it safely via
RingBuffer<SomeFancyElement>::AccessResult res = elems.getAt(2); if (res.valid) { do something with res.item of Type SomeFancyElement };
Unfortunatelly, I get a compiler error which says
"AccessResult" struct member undefined.
Is there some work-around?
Thank you very much!