Thread: How do I inherit static data members ?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I would probably use the generic overload for primitive types, then provide a Serializable& overload, but no more, causing compile errors instead of silent "failure."
    Anyway, I put that out there not just as a "lecture," but also as information to whomever else may be reading and to point out boost, of course.
    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. #17
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    that wouldn't cause compile errors.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Having a non-appropriate overload would cause a compile error.
    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. #19
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    you can't overload your way into compile errors, the template always picks up the 'miscellaneous'. you can only overload your way into alternate paths. the only way that could possibly work would be with something like this:

    Code:
    template<class T,class U>
    class Conversion
    {
        typedef char Small;
        class Big{char arr[2];};
        static Small Test(U);
        static Big Test(...);
        static T& MakeT();
    public:
        enum
        {
            exists = sizeof(Test(MakeT()))==sizeof(Small)
        };
    };
    
    template<typename T> void Serializer::pack(T& t)
    {
        static_assert(Conversion<T,int>::exists,"packed types must be POD");
    }
    Last edited by m37h0d; 03-12-2012 at 07:57 AM.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    My point was to remove the generic overload to cause compile errors on purpose.
    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. #21
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    you said you'd use it for POD.

    the generic overload is extremely powerful. it lets you serialize containers recursively, which allows you to handle containers-of-containers, and the like with no additional effort.

    providing overloads for the standard containers plus a serializeable interface, along with the POD-check above in the ultimate call that packs the data members into the byte buffer works very well.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by m37h0d View Post
    you said you'd use it for POD.
    Not POD. Primitive types.
    Although, even primitive types are dangerous.
    Although then again, think about it, providing overloads for the fixed-size types in C++11 and doing checks for endianess, it wouldn't be so bad.
    POD types are still dangerous since we cannot predict padding.

    providing overloads for the standard containers plus a serializeable interface, along with the POD-check above in the ultimate call that packs the data members into the byte buffer works very well.
    For primitive types, but yes, I am inclined to agree. You may wish to extend it somehow to make it easy to write some code to allow for easily writing code to handle custom containers. Although I suppose one might be able to derive from Serializable or perhaps the class exposes some interface that can easily be overloaded. I digress.
    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. #23
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    darth vader is riding a unicycle playing a bagpipe.

    your argument is invalid.

    Darth Vader bagpipe unicycle - YouTube





    happy monday

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-17-2011, 11:22 PM
  2. Replies: 1
    Last Post: 04-29-2011, 08:41 PM
  3. static data members in structure
    By bhagwat_maimt in forum C++ Programming
    Replies: 9
    Last Post: 11-06-2006, 11:47 AM
  4. static data members
    By ichijoji in forum C++ Programming
    Replies: 2
    Last Post: 07-05-2006, 05:18 PM
  5. static and non-static data members
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2002, 10:06 AM