Though implementation problem

This is a discussion on Though implementation problem within the C++ Programming forums, part of the General Programming Boards category; OK, here's another tough implementation problem. CTmplStringBase will have one of two functions depending on what type T is, so ...

  1. #1
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,633

    Tough implementation problem

    OK, here's another 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>,
    Because it wants access to specialized template member functions:
    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;
    	};
    But StrConversion wants to return objects of CTmplStringBase, so I get circular dependencies.
    Last edited by Elysia; 05-11-2008 at 10:00 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    Your irrational fear of non-member functions has caused you to do all sorts of bizarre things...

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,633
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    Quote Originally Posted by Elysia View Post
    Fear? Hardly. They're evil.
    I don't like them; not I fear them.
    You're inheriting a String class from something called StrConversion. Your design is critically ill, and I don't mean that in the rapper sense.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,633
    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.
    Last edited by Elysia; 05-11-2008 at 10:24 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    Quote Originally Posted by Elysia View Post
    Then suggest a better solution, which does not include non-member functions.
    I can't give you what doesn't exist.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,633
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    Quote Originally Posted by Elysia View Post
    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.
    You're willing to accept "big hacks" but not a non-member function. Okay..

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,780
    What's wrong with providing ToUTF16 and ToANSI as free functions?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,633
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    Quote Originally Posted by Elysia View Post
    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.
    You're high.

  12. #12
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    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.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,780
    OOP is more important than free functions and algorithms to me.
    As far as I can tell your code remains object oriented with those two functions as free functions.

    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
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    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...

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,633
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 20 1234567891011 ... LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. implementation file
    By bejiz in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2005, 12:59 AM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. Memory Problem - I think...
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 10-24-2001, 12:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21