CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 42
  1. #16
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by Paul McKenzie View Post
    I've mentioned to you on other threads that the compiler used by Dev-C++ and MingW is what is important. That compiler happens to be gcc.

    The gcc compiler already supports everything that you are looking for.

    http://gcc.gnu.org/projects/cxx0x.html

    MingW also uses gcc to compile projects. Dev-C++ (once again) is an IDE that just happens to have an old version of gcc already plugged into it. If you take a look at the link I gave you above, and do a little searching on the Internet, you should be able to upgrade MingW to use the latest version of gcc.

    The boost libraries are extensively tested with gcc and Visual Studio, and I would say the two platforms that must compile successfully before being accepted by boost.org.

    As to IDE's, there is CodeBlocks, which is up-to-date. Do an Intenet search and you will find other IDE's.

    Regards,

    Paul McKenzie
    seems that i didn't understand that before..thanks
    1 thing: the CodeBlocks suports C++11?

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by Cambalinho View Post
    seems that i didn't understand that before..thanks
    1 thing: the CodeBlocks suports C++11?
    You're still confused.

    CodeBlocks is an Integrated Development Environment. It is not a compiler. CodeBlocks, Dev-C++, and even Visual Studio do not know how to compile C++ source code. What does know how to compile C++ source code is the underlying compiler that is used in these programs.

    For CodeBlocks, you can basically plug any compiler into it, but most of the time, people configure CodeBlocks to use MingW or gcc. The latest version of gcc is 4.8 (I believe), and it supports all that have been mentioned to you so far.

    For Dev-C++, it was designed for gcc 3.x, which is close to 10 years old and out-of-date. Version 3.x of gcc is ok if you're purely interested in only C++ 98 standard, but anything beyond that, 3.x is not going to help you.

    For Visual Studio, the compiler used is cl.exe (and cl.exe is being updated to keep up to the current standard (C++ 11). I've heard of Intel compiler being able to be plugged into the Visual Studio IDE, but have never tried it.

    Basically what I'm saying to you is that every IDE that I know of uses 2 or 3 executables:

    1) The compiler that compiles the source code to object code (gcc.exe, cl.exe, etc.)
    2) The linker program that links the various object code (ld.exe, link.exe, etc.)
    3) A debugger program or module that allows you to debug the program (gdb.exe, ddd.exe, Visual Studio's integrated debugger, etc.).

    Optionally, an IDE may just build a "make" file and call a program that knows how to read the make file and build the program.

    Except for 3), where the IDE needs to understand the debugger symbols and position the debugger indicator on the correct line, items 1) and 2) requires just calling the executable that compiles and then links.

    As a matter of fact, you don't even need an IDE to develop a program. The reason why IDE's are used is that using the command-line for very large projects becomes very difficult to maintain (unless you have batch files to compile and link large projects, and some people/companies do just that, and that is to create batch files/make files and forget about IDE's to build their programs).

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; August 24th, 2013 at 06:15 PM.

  3. #18
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by Paul McKenzie View Post
    You're still confused.

    CodeBlocks is an Integrated Development Environment. It is not a compiler. CodeBlocks, Dev-C++, and even Visual Studio do not know how to compile C++ source code. What does know how to compile C++ source code is the underlying compiler that is used in these programs.

    For CodeBlocks, you can basically plug any compiler into it, but most of the time, people configure CodeBlocks to use MingW or gcc. The latest version of gcc is 4.8 (I believe), and it supports all that have been mentioned to you so far.

    For Dev-C++, it was designed for gcc 3.x, which is close to 10 years old and out-of-date. Version 3.x of gcc is ok if you're purely interested in only C++ 98 standard, but anything beyond that, 3.x is not going to help you.

    For Visual Studio, the compiler used is cl.exe (and cl.exe is being updated to keep up to the current standard (C++ 11). I've heard of Intel compiler being able to be plugged into the Visual Studio IDE, but have never tried it.

    Basically what I'm saying to you is that every IDE that I know of uses 2 or 3 executables:

    1) The compiler that compiles the source code to object code (gcc.exe, cl.exe, etc.)
    2) The linker program that links the various object code (ld.exe, link.exe, etc.)
    3) A debugger program or module that allows you to debug the program (gdb.exe, ddd.exe, Visual Studio's integrated debugger, etc.).

    Optionally, an IDE may just build a "make" file and call a program that knows how to read the make file and build the program.

    Except for 3), where the IDE needs to understand the debugger symbols and position the debugger indicator on the correct line, items 1) and 2) requires just calling the executable that compiles and then links.

    As a matter of fact, you don't even need an IDE to develop a program. The reason why IDE's are used is that using the command-line for very large projects becomes very difficult to maintain (unless you have batch files to compile and link large projects, and some people/companies do just that, and that is to create batch files/make files and forget about IDE's to build their programs).

    Regards,

    Paul McKenzie
    thanks for all... tomorrow i will see that, thanks for all..thanks

  4. #19
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    i download the CodeBlocks but didn't came with compiler
    i'm trying download the gcc, but i can't find the right download. can you help me?
    it's only 1 exe or others anotherone for windows programing?

  5. #20
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by Cambalinho View Post
    i download the CodeBlocks but didn't came with compiler
    i'm trying download the gcc, but i can't find the right download. can you help me?
    it's only 1 exe or others anotherone for windows programing?
    As per Pauls useful detailed explanation in post #17, CodeBlocks is not a compiler and doesn't come with a compiler. You are confusing an IDE (such as CodeBlocks) with the compiler (such as gcc).

    The IDE allows you to create and modify your source code and calls the specified compiler/linker with the required options when needed.

    The compiler (eg gcc) compiles the source code and produces object (.obj) files.

    The linker takes these .obj files (and other files such as .lib files etc) and produces the .exe file.

    To install gcc 4.8.1 under windows I suggest you have a look at these links for info.

    http://www.cplusplus.com/forum/windows/106380/
    (the second post gives links to the 32 or 64 bit windows version)

    http://stackoverflow.com/questions/1...-windows-7-x64
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #21
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by 2kaud View Post
    As per Pauls useful detailed explanation in post #17, CodeBlocks is not a compiler and doesn't come with a compiler. You are confusing an IDE (such as CodeBlocks) with the compiler (such as gcc).

    The IDE allows you to create and modify your source code and calls the specified compiler/linker with the required options when needed.

    The compiler (eg gcc) compiles the source code and produces object (.obj) files.

    The linker takes these .obj files (and other files such as .lib files etc) and produces the .exe file.

    To install gcc 4.8.1 under windows I suggest you have a look at these links for info.

    http://www.cplusplus.com/forum/windows/106380/
    (the second post gives links to the 32 or 64 bit windows version)

    http://stackoverflow.com/questions/1...-windows-7-x64
    thanks for all
    i have more questions, but i must do another topic
    thanks for all

  7. #22
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by Cambalinho
    i download the CodeBlocks but didn't came with compiler
    Quote Originally Posted by 2kaud
    CodeBlocks is not a compiler and doesn't come with a compiler.
    Actually, some of the official packages of CodeBlocks do come with a compiler, in particular some version of the MinGW port of GCC for two of the Windows installation packages: CodeBlocks binary packages.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  8. #23
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by laserlight View Post
    Actually, some of the official packages of CodeBlocks do come with a compiler, in particular some version of the MinGW port of GCC for two of the Windows installation packages: CodeBlocks binary packages.
    now the IDE is working normaly
    1 - dowload the IDE;
    2 - download MinGW compiler;
    (more easy for have the last version)
    3 - now we must 'tell' the IDE where is the compiler and choose the folders where is it. and tell it the files names inclued the compiler too

    now i need ask something: these code works fine with C++ 11???

    Code:
    #include <algorithm>
    #include <typeinfo>
    
    class BaseHolder
    {
        public:
            virtual ~BaseHolder(){}
    };
    
    template<typename T>
    class HoldData : public BaseHolder
    {
        public:
            HoldData(const T& t_) : t(t_){}
        private:
            T t;
    };
    
    class variant
    {
        public:
            template<typename T>
            Variant(const T& t) : data(new HoldData<T>(t)){}
            ~Variant(){delete data;}
        private:
            BaseHolder* data;
    };
    because i'm geting some errors in these lines:

    Code:
    Variant(const T& t) : data(new HoldData<T>(t)){}
            ~Variant(){delete data;}
    or do i need do more changes in options?

  9. #24
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    i found the error(C is case sensitive lol):
    Code:
    class variant {
    public:
      // construct/copy/destruct
      variant();
      variant(const variant &);
      variant(variant &&);
      template<typename ValueType> variant(const ValueType &);
      template<typename ValueType> variant(ValueType &&);
      variant & operator=(const variant &);
      variant & operator=(variant &&);
      template<typename ValueType> variant & operator=(const ValueType &);
      template<typename ValueType> variant & operator=(ValueType &&);
      ~variant();
    
      // modifiers
      variant & swap(variant &);
    
      // queries
      bool empty() const;
      const std::type_info & type() const;
    };
    these code don't give me errors... but when i use it:

    Code:
    /Write
        void Write(variant var1, variant var2="", variant var3="", variant var4="",  variant var5="",  variant var6="")
        {
    			cout << var1 << var2 << var3 << var4 << var5 << var6;
        }
    i get 3 errors:

    1 - "In member function 'void Console::Write(variant, variant, variant, variant, variant, variant)'";

    2 - "|169|error: cannot bind 'std:stream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&'|";

    3 - "|error: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std:perator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = variant]'||".

    what i'm doing wrong?

  10. #25
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: is possible create a any type variable(1 variable that accept any type of values)

    or do i need do more changes in options?
    See http://gcc.gnu.org/projects/cxx0x.html

    You might need the -std=c++11 option
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  11. #26
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by 2kaud View Post
    See http://gcc.gnu.org/projects/cxx0x.html

    You might need the -std=c++11 option
    i think now it's selected:
    in menu: Settings - Compiler...
    then in Compiler Settings tab - Compiler flags sub tab i select(in all categories):

    "have g++ follow the coming c++0x ISO c++ language standard [-std=c++0x]"

    and

    "have g++ follow the c++11 ISO c++ language standard [-std=c++11]"

    it's ok, right?
    (see my last post too, please)

  12. #27
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: is possible create a any type variable(1 variable that accept any type of values)

    You probably should choose only one of them, depending on the version of g++. I think 4.7 uses -std=c++11 whereas earlier versions use -std=c++0x (as C++11 had not been published at the time).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  13. #28
    Join Date
    Apr 2009
    Posts
    1,355

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Quote Originally Posted by laserlight View Post
    You probably should choose only one of them, depending on the version of g++. I think 4.7 uses -std=c++11 whereas earlier versions use -std=c++0x (as C++11 had not been published at the time).
    i use MinGWx32-4.8.1
    but if i do change it for only -std=c++11, the errors continue, when i use variant variables

  14. #29
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Code:
    //Write
        void Write(variant var1, variant var2="", variant var3="", variant var4="",  variant var5="",  variant var6="")
        {
    			cout << var1 << var2 << var3 << var4 << var5 << var6;
        }
    i get 3 errors:
    Quite right! In c++, stream insertion (<<) is done via operator overloading of the << operator. By default, << operator overloads are provided for the in-built types (int, char *etc ) and for the string class. If you want to output data from your own type or class (eg variant) then you will need to supply your own version of the << operator that works for that type/class. If you want cout to work with the class variant, then you will need something like this

    Code:
    //IO stream insertion (output)
    ostream& operator <<(ostream& os, const variant& vt)
    {
            //code to go here to output data from vt as required
    	return (os);
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  15. #30
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: is possible create a any type variable(1 variable that accept any type of values)

    Now that you have a c++11 compiler, you might want to revisit where all this started - How can I convert write procedure to cout

    http://forums.codeguru.com/showthrea...cedure-to-cout

    and see my post #15 with the solution using variadic templates. As gcc 4.8.1 supports variadic templates, this code should compile and give you the write function you originally wanted without using the variant class - which I suspect is going to give more trouble than it's worth.

    Code:
    #include <iostream>
    using namespace std;
    
    void write()
    {
       cout << " ";
    }
    
    template <typename A, typename ...B>
    void write(A argHead, B... argTail)
    {
       cout << argHead << " ";
       write(argTail...);
    }
    
    
    int main(void)
    {
       write(1, 2, "qwerty", 4.45, "five", 6);
       return 0;
    }
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured