Moving C++/CLI Properties Out Of Headers
164 words.
A while back I railed against C++/CLI for its nonsensical inability to separate property implementations from the header file. Well, it turns out you can do it - it’s just not widely reported. Almost every example of a C++/CLI property shows it implemented in the header file. But thankfully I stumbled upon an article about this very subject: Splitting Properties Between Header And Implementation Files In C++/CLI.
Old Class.h:
7 public ref class Effect
8 {
9 private:
10 Route^ componentChain;
11
12 public:
13 property Route^ ComponentChain
14 {
15 Route^ get(void) { return this->componentChain; }
16 }
17 };
New Class.h:
7 public ref class Effect
8 {
9 private:
10 Route^ componentChain;
11
12 public:
13 property Route^ ComponentChain
14 {
15 Route^ get(void);
16 }
17 };
New Class.cpp:
24 Route^ Effect::ComponentChain::get(void)
25 {
26 return this->componentChain;
27 }
The key is the Class::Property::get and Class::Property::set syntax that I’d not seen documented anywhere before. Hopefully now that there are two articles about this, it will move up higher in Google searches.
Sorry, new comments are disabled on older posts. This helps reduce spam. Active commenting almost always occurs within a day or two of new posts.