![]() |
| | #1 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Tough implementation problem CTmplStringBase will have one of two functions depending on what type T is, so naturally to this, a specialized template would be required. Unfortunately, that means I have to create a new class and inherit from, else I would have to remake the entire class in the specialization. But this new class returns an object of the class it inherits from, so it, in turn, needs the inheriting class to be defined first. But then, the code won't compile because CTmplStringBase would try to derive from an undefined class. So what's a solution to this? CTmplStringBase wants to derive from StrConversions: Code: template<typename T, typename Traits> class CTmplStringBase: public StrConversion<T>, Code: template<typename T> class StrConversion { };
template<> class StrConversion<char>
{
public:
CStringExW ToUTF16();
private:
virtual const char* GetData() = 0;
};
template<> class StrConversion<wchar_t>
{
public:
CStringExA ToANSI();
private:
virtual const wchar_t* GetData() = 0;
};
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
Last edited by Elysia; 05-11-2008 at 10:00 AM. | |
| Elysia is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Your irrational fear of non-member functions has caused you to do all sorts of bizarre things... |
| brewbuck is offline | |
| | #3 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Fear? Hardly. They're evil. I don't like them; not I fear them. But regardless. If I wanted, I could just add two methods to the class, in which case they would show up for both Unicode and ansi specialization of the class (the same as for non-member functions). But I wanted something extra - to include a member only for specific specializations.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #4 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| |
| brewbuck is offline | |
| | #5 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Then suggest a better solution (I don't like it anymore than you do), which does not include non-member functions. So far as I see, I'm hitting a language barrier and have to retort to some workaround to make it work.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
Last edited by Elysia; 05-11-2008 at 10:24 AM. | |
| Elysia is offline | |
| | #6 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| |
| brewbuck is offline | |
| | #7 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Oh sure, there does exist solutions. One I can think of is some workarounds. Temporary object inside class to return by reference. Or better, return via a smart pointer. Those seems like big hacks to me, though, and was wondering if there's another solution or what another dev would do to make it work like it, if they would at all.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #8 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
| |
| brewbuck is offline | |
| | #9 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| What's wrong with providing ToUTF16 and ToANSI as free functions?
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #10 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| They are free functions (currently) and would like to integrate them into the class, preferably as implementations that exist only in appropriate specializations, if possible. So long as it doesn't have a big impact on performance, I'm willing to accept hacks if it's possible to get around. OOP is more important than free functions and algorithms to me.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #11 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
| |
| brewbuck is offline | |
| | #12 |
| Afraid of widths Join Date: Apr 2008 Location: Chicago
Posts: 887
| This is why Dr. Stroustrup designed C++ to support procedural, object-oriented, and generic programming. He understands that one paradigm isn't best for all problems. I'm not sure why you think every problem is best solved with objects. |
| medievalelks is offline | |
| | #13 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Quote:
I suppose if you really insist you could make them static member functions instead, like what the Java programmers would do
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #14 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Elysia has apparently already decided that all objects should be all things to all people. I'm waiting for the realization that this implies an infinite amount of code, but it seems to be a long time coming... |
| brewbuck is offline | |
| | #15 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| I don't like the idea to be limited to one paradigm either. I use them as I see fit. However, to these kind of things, classes are best IMHO. All functionality for an object to be grouped inside its object and not broken out. Why is it so difficult to learn C++ and not VB or Java (unsure about this one) or such languages, I wonder? Because everything is neatly organized into one place. If a programmer has to rely on algorithms to get things done (and I mean simple tasks), or go browse through a namespace that's not named in the docs, things DO get harder. Difficulty is what I try to avoid. No wonder C++ is difficult to learn. And some don't seem to understand my point either... Classes, like functions, can be extended. It's your job to make sure they can be. They should be. Otherwise you did something wrong. One class should be one thing. Don't add everything into it. But a string class should have certain things, such as ToLower/ToUpper, which the standard library seem to lack. Classes can grow just as free functions can grow. Now, the problem is to find a way to make it possible for the classes to grow similar to free functions. I don't I'd use static members, though. They would appear inside the class namespace. I'd rather make them free and move them into the Strings namespace... Neatly organized.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| WS_POPUP, continuation of old problem | blurrymadness | Windows Programming | 1 | 04-20-2007 06:54 PM |
| Laptop Problem | Boomba | Tech Board | 1 | 03-07-2006 06:24 PM |
| implementation file | bejiz | C++ Programming | 5 | 11-28-2005 01:59 AM |
| Sorting problem.. well actually more of a string problem | fatdunky | C Programming | 5 | 11-07-2005 11:34 PM |
| Memory Problem - I think... | Unregistered | C Programming | 4 | 10-24-2001 12:14 PM |