About Store Forum Documentation Contact
Donations:
345$/mo



Post Reply 
code editor 'flaw'
Author Message
yvanvds Offline
Silver Supporter

Post: #1
code editor 'flaw'
Take a look at the code example below. Considering that the code editor should make things easier and, more specifically, pointer notation is avoided, I would not consider this very nice code.

if objectPtr->operator()() is needed to get a value from a gui object, it should be possible to just write objectPtr() instead. If not, it might be more logical to get the value with normal member function instead of an operator, so that objectPtr.get() is possible.

Not that I urgently need this. But I'm using esenthel in a beginners programming class now and the operator notation is much more advanced than it should be.

Regards,

yvan

Code:
GuiObjs topwindow;
Slider * s;
float x;

void InitPre() {
   DataPath("C:/EsenthelEngineSDK/Data");
   Paks.add("engine.pak");
}

bool Init()
{
   topwindow.load("Gui/obj/test.gobj");
   Gui += topwindow;
  
   s = topwindow.findSlider("slider");
  
   return true;
}

void Shut() {}

bool Update() {
   if(Kb.bp(KB_ESC))return false;
   x = s->operator()(); // works
   x = s();             // i think this should work but it does not
   Gui.update();
   return true;
}

void Draw() {
   D.clear(WHITE);
   Circle(x, 0, 0).draw(BLUE);
   Gui.draw();
}
10-25-2012 11:14 PM
Find all posts by this user Quote this message in a reply
laugan Offline
Member

Post: #2
RE: code editor 'flaw'
try this:
Code:
x = (*s)();
s is a pointer (or i don't know how to say in english), you can access Slider's variables through
Code:
s->
if you use * before a pointer you will get access not to pointer's address, but to object (which this pointer references).
ahh sorry, you write about code editor and not-using pointers.

Anyway this info can be useful to others
(This post was last modified: 10-26-2012 05:31 AM by laugan.)
10-26-2012 05:29 AM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Silver Supporter

Post: #3
RE: code editor 'flaw'
Yes, it's not about how to do it. Merely the fact that it could be easier for people if they use the code editor. But thanks anyway, Laugan.
10-26-2012 05:21 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: code editor 'flaw'
@yvands: I'm not doing this because, just as having operator() you could have custom operator[] method.
and similar to s() to call operator() you could use s[] to call operator[], however for pointers the [] is already defined in the c++ to access following elements starting from the s pointer
11-07-2012 04:30 PM
Find all posts by this user Quote this message in a reply
Post Reply