quote:Original post by YourOtherLeftquote:Original post by superpigquote:Original post by YourOtherLeft
void Set##var(const type &val) { this->val ;}
Uhm... how exactly does that work?
When you use DEFINE_VAR(Name) you will see in the definition that the protected member is called ''var'' the ##var tells the compiler that when the is replaced ie GetName() it looks at the variable defined Name. Not sure how better to describe it, any offers?
No, no, the token-pasting stuff is fine - I use it all the time - but when you actually use the macro, looks what happens:
//here''s the original macro#define DEFINE_VARIABLE(type,var) public: type Get##var() const { return var; } void Set##var(const type &val) { this->val ;} protected: type var;//here''s me using itDEFINE_VARIABLE(int, Foo)//here''s the output from the preprocessor public: int GetFoo() const { return foo; } void SetFoo(const int &val) { this->val; } protected: int foo;
Now please tell me, what does the SetFoo function actually do, hmm?
Also, are you sure you don''t have to use the token-pasting operator a bit more? I''d probably write that macro like:
#define DEFINE_VARIABLE(type,var) public: type Get##var##() const { return ##var##; } void Set##var##(const type &val) { this->val ;} protected: type var##;
I''m not sure what the rules are about trailing characters on tokens in macros...
Richard "Superpig" Fine
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4
ry. .ibu cy. .y''ybu. .abu ry. dy. "sy. .ubu py. .ebu ry. py. .ibu gy." fy. .ibu ny. .ebu
OpenGL is a language