Like Tree1Likes

How do I inherit static data members ?

This is a discussion on How do I inherit static data members ? within the C++ Programming forums, part of the General Programming Boards category; I would probably use the generic overload for primitive types, then provide a Serializable& overload, but no more, causing compile ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,887
    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
    839
    that wouldn't cause compile errors.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,887
    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
    839
    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 08:57 AM.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,887
    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
    839
    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
    Posts
    22,887
    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
    839
    darth vader is riding a unicycle playing a bagpipe.

    your argument is invalid.

    Darth Vader bagpipe unicycle - YouTube





    happy monday
    QuantumPete likes this.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-18-2011, 12:22 AM
  2. Replies: 1
    Last Post: 04-29-2011, 09: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, 06:18 PM
  5. static and non-static data members
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2002, 11:06 AM

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