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

This is a discussion on Am I doing something wrong or does my compiler not understand this? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by laserlight hmm... MSVC10 will not support variadic templates, but maybe some new version of g++ supports that ...

  1. #31
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,823
    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
    21,992
    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.
    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

  3. #33
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,823
    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,893
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,823
    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,893
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,823
    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
    21,992
    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.
    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

  9. #39
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,823
    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
    839
    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-18-2009 at 11:00 PM.

Page 3 of 3 FirstFirst 123
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, 01: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


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