Thread: Am I doing something wrong or does my compiler not understand this?

  1. #31
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by laserlight View Post
    hmm... MSVC10 will not support variadic templates, but maybe some new version of g++ supports that feature (or will soon support it).
    There is no word yet that it supports it, true, but neither is it feature complete yet (and they did say it was probably going to get some more functions before the public release).
    So atm, no it doesn't support them, but hold your breath - perhaps the final version does.
    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. #32
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Elysia
    There is no word yet that it supports it, true, but neither is it feature complete yet (and they did say it was probably going to get some more functions before the public release).
    So atm, no it doesn't support them, but hold your breath - perhaps the final version does.
    I will not be holding my breath. Read Jonathan Caves' (joncaves) reply in C++0x language feature checklist.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #33
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That is pretty disappointing. So few features implemented. I will still hold my breath that they change their minds.
    Multitasking - maybe? It's one of the big things they're touting in this release...
    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. #34
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    This is not about changing their minds, it's about keeping a schedule.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #35
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I know that -_-
    What I mean is schedules can change.
    Example, features can be dropped, added or changed.
    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. #36
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Ah, but that's generally a marketing decision. Especially in a company as big as MS.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #37
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ya, so if enough decides they want other features (especially companies), Microsoft will scramble to comply. So that's why I can hope. Or we can hope
    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. #38
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Elysia
    Ya, so if enough decides they want other features (especially companies), Microsoft will scramble to comply. So that's why I can hope. Or we can hope
    Yes, we can hope
    Quote Originally Posted by joncaves
    We will add more C++-0x features in the future - but what and when is currently unknown: it all depends on user feedback.
    I guess my own pet missing features would be nullptr, template typedefs and explicit conversion functions. Oh, and maybe concepts and the range based for loop, but perhaps introducing concepts is a more far reaching change than the three that I listed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #39
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I wanted to see nullptr, explicit conversion functions, concepts and strongly typed enums... At least. Oh and the new string literals.
    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.

  10. #40
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    i think i am approaching something interesting

    this all works quite nicely imo:

    Code:
    //metaObject.h
    #ifndef metaObjectH
    #define metaObjectH
    #include <vector>
    #include "tmember.h"
    
    class member;
    class metaObject
    {
        friend class member;
        private:
            std::vector<member*>members;
        public:
            template<typename H,typename T>metaObject(typelist<H,T> t)
            {
                tmembers<typelist<H,T> >(*this);
            }
            template<typename T> void get(unsigned int index,T& lvalue)
            {
                tmembers<T>* tm =static_cast<tmembers<T> *>(members[index]);
                lvalue = *tm->value;
            }
            template<typename T> void set(unsigned int index,T* rvalue)
            {
                tmembers<T>* tm =static_cast<tmembers<T> *>(members[index]);
                tm->value=rvalue;
            }
    
    };
    
    
    
    //---------------------------------------------------------------------------
    #endif
    Code:
    //tmember.h
    
    #ifndef tmemberH
    #define tmemberH
    #include "member.h"
    #include "typelist.h"
    
    template<typename T>class tmembers : public member
    {
        friend class metaObject;
        protected:
            tmembers(metaObject& obj):
                member(obj)
            {
            }
            tmembers(){}
            T* value;
    };
    
    template<typename H,typename T>class tmembers< typelist<H,T> >:
        public virtual tmembers<H>,
        public virtual tmembers<T>
    {
        friend class metaObject;
        protected:
            tmembers(metaObject &obj):
                member(obj),
                tmembers<H>(obj),
                tmembers<T>(obj)
            {
            }
    };
    template<typename H>class tmembers< typelist<H,end> > :
        public virtual member,
        public virtual tmembers<H>
    {
        friend class metaObject;
        protected:
            tmembers(metaObject &obj):
                tmembers<H>(obj)
            {
            }
            tmembers(){}
    };
    
    template<>class tmembers< end >
    {
        friend class metaObject;
        protected:
            tmembers()
            {
            }
    };
    
    //---------------------------------------------------------------------------
    #endif
    Code:
    //member.h
    
    #ifndef memberH
    #define memberH
    //---------------------------------------------------------------------------
    class metaObject;
    class member
    {
        protected:
        member(metaObject &obj);
        member(){};
    };
    
    #endif
    Code:
    //member.cpp
    
    #include "metaObject.h"
    #pragma hdrstop
    
    #include "member.h"
    
    //---------------------------------------------------------------------------
    
    member::member(metaObject &obj)
    {
        obj.members.push_back(this);
    }
    Code:
    #include "metaObject.h"
    int main(int argc, char* argv[])
    {
        metaObject *o = new metaObject(types<int,double,char>::type());
        int *d=new int(1);
        int d2(0);
        o->set(1,d);
        o->get(1,d2);
        *d=0;
        o->get(1,d2);
    
        return 0;
    }
    if you try to get or set with an incompatible type, you get a compile time error.

    however, what i really wanted to do was this:

    Code:
    class member;
    class metaObject
    {
        friend class member;
        private:
            std::vector<member*>members;
        public:
            template<typename H,typename T>metaObject(typelist<H,T> t,...)
            {
                va_list ap;
                tmembers<typelist<H,T> >(*this,ap);
                va_end(ap);
            }
            template<typename T> void get(unsigned int index,T& lvalue)
            {
                tmembers<T>* tm =static_cast<tmembers<T> *>(members[index]);
                lvalue = *tm->value;
            }
            template<typename T> void set(unsigned int index,T* rvalue)
            {
                tmembers<T>* tm =static_cast<tmembers<T> *>(members[index]);
                tm->value=rvalue;
            }
    
    };
    
    ...
    
    //---------------------------------------------------------------------------
    
    #ifndef tmemberH
    #define tmemberH
    #include <stdarg>
    #include "member.h"
    #include "typelist.h"
    
    template<typename T>class tmembers : public member
    {
        friend class metaObject;
        protected:
            tmembers(metaObject& obj,va_list ap):
                member(obj),
                value(va_arg(ap,T))
            {
            }
            tmembers(){}
            T value;
    };
    
    template<typename H,typename T>class tmembers< typelist<H,T> >:
        public virtual tmembers<H>,
        public virtual tmembers<T>
    {
        friend class metaObject;
        protected:
            tmembers(metaObject& obj,va_list ap):
                member(obj),
                tmembers<H>(obj,ap),
                tmembers<T>(obj,ap)
            {
            }
    };
    
    template<typename H>class tmembers< typelist<H,end> > :
        public virtual member,
        public virtual tmembers<H>
    {
        friend class metaObject;
        protected:
            tmembers(metaObject& obj,va_list ap):
                member(obj),
                tmembers<H>(obj,ap)
            {
            }
            tmembers(){}
    };
    
    template<>class tmembers< end >
    {
        friend class metaObject;
        protected:
            tmembers()
            {
            }
    };
    
    //---------------------------------------------------------------------------
    #endif
    however, this:

    Code:
    metaObject *o = new metaObject(types<int,double,char>::type(),1,1.234,'a');
    begets this:

    [C++ Error] Unit1.cpp(11): E2285 Could not find a match for 'metaObject::metaObject(typelist<int,typelist<doub le,typelist<char,end> > >,int,double,char)'

    is the only other alternative to instantiate the variables inside types?
    Last edited by m37h0d; 01-19-2009 at 12:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. compiler differences
    By white in forum C Programming
    Replies: 1
    Last Post: 02-18-2005, 02:58 PM
  3. Comile problem using latest Dev C++ Compiler
    By shiny_dico_ball in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2003, 05:32 PM
  4. C Compiler
    By SAMSEIED in forum C Programming
    Replies: 5
    Last Post: 06-06-2002, 05:44 PM
  5. What's wrong with Micorsoft Visual C++?
    By knave in forum C++ Programming
    Replies: 9
    Last Post: 10-04-2001, 08:02 AM

Tags for this Thread