boost::function



  • ricky schrieb:

    aber

    boost::function< int( int a ) > f = foo;
    
        std::cout << f( 1 ) << std::endl;
    

    aber hier wird ja auch schon zur compilezeit bestimmt was aufgerufen wird?

    #include <iostream>
    #include <boost/function.hpp>
    
    int foo( int a )
    {
        return a;
    }
    
    int bar( int a )
    {
        return 42;
    }
    
    int main( )
    {
        int a;
        std::cin >> a;
    
        boost::function< int( int a ) > f;
    
        if( a < 10 ) {
    
            f = foo;
    
        } else {
    
            f = bar;
        }
    
        std::cout << f( a ) << std::endl;
    }
    

    💡

    Greetz, Swordfish



  • vielleicht so @Swordfish:

    #include <iostream>
    #include <boost/function/function1.hpp>
    
    int foo( int a )
    {
         return a;
    }
    
    int main( )
    {
         boost::function1< int, int> f;
    	 f = foo;
         std::cout << f( 1 ) << std::endl;
    }
    


  • @swordfish
    Dein letztes Beispiel compiliert und läuft bei mir einwandfrei mit VC8.0 😕



  • 1310-Logik schrieb:

    War zu langsam mit Editieren

    function1 sollte es bei Dir sein:

    #include <boost/function/function1.hpp>
    
    boost::function1< int(int a) >;
    
    #include <iostream>
    #include <boost/function/function1.hpp>
    /* 003 */ 
    /* 004 */ int foo( int a )
    /* 005 */ {
    /* 006 */     return a;
    /* 007 */ }
    /* 008 */ 
    /* 009 */ int main( )
    /* 010 */ {
    /* 011 */     boost::function1< int, int > f = foo;
    /* 012 */ 
    /* 013 */     std::cout << f( 1 ) << std::endl;
    /* 014 */ }
    

    MSVC v7.1 schrieb:

    main.cpp
    d:\root\projects\_Visual Studio\test\main.cpp(11) : error C2440: 'Initialisierung' : 'int (__cdecl *)(int)' kann nicht in 'boost::function1' konvertiert werden
    with
    [
    R=int,
    T0=int,
    Allocator=int
    ]
    Quelltyp konnte von keinem Konstruktor angenommen werden, oder die Überladungsauflösung des Konstruktors ist mehrdeutig

    😕

    Greetz, Swordfish



  • #include <iostream>
    #include <boost/function.hpp>
    
    int foo( int a )
    {
        return a;
    }
    
    int bar( int a )
    {
        return 42;
    }
    
    int main( )
    {
        int a;
        std::cin >> a;
    
        boost::function< int( int a ) > f;
    
        if( a < 10 ) {
    
            f = foo;
    
        } else {
    
            f = bar;
        }
    
        std::cout << f( a ) << std::endl; 
    
    	std::cout << std::endl << "Hit enter to close window" << std::endl;
    	std::cin.clear();
    	std::cin.ignore( std::cin.rdbuf()->in_avail() );
        std::cin.get();
    	return 0;
    }
    

    Compiling...
    Main.cpp
    Compiling manifest to resources...
    Linking...
    LINK : C:\...\Visual Studio 2005\Projects\Boost test\Debug\Boost test.exe not found or not built by the last incremental link; performing full link
    Embedding manifest...
    Build log was saved at "file://c:\Dokumente und Einstellungen\Sebi\Eigene Dateien\Visual Studio 2005\Projects\Boost test\Boost test\Debug\BuildLog.htm"
    Boost test - 0 error(s), 0 warning(s)
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

    😕



  • #include <iostream>
    #include <boost/function.hpp>
    /* 003 */
    /* 004 */ int foo( int a )
    /* 005 */ {
    /* 006 */     return a;
    /* 007 */ }
    /* 008 */
    /* 009 */ int main( )
    /* 010 */ {
    /* 011 */     boost::function< int(int a) > f = foo;
    /* 012 */
    /* 013 */     std::cout << f( 1 ) << std::endl;
    /* 014 */ }
    

    ------ Rebuild All started: Project: Boost test, Configuration: Debug Win32 ------
    Deleting intermediate and output files for project 'Boost test', configuration 'Debug|Win32'
    Compiling...
    Main.cpp
    Compiling manifest to resources...
    Linking...
    LINK : C:\...\Visual Studio 2005\Projects\Boost test\Debug\Boost test.exe not found or not built by the last incremental link; performing full link
    Embedding manifest...
    Build log was saved at "file://c:\Dokumente und Einstellungen\Sebi\Eigene Dateien\Visual Studio 2005\Projects\Boost test\Boost test\Debug\BuildLog.htm"
    Boost test - 0 error(s), 0 warning(s)
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

    Ausgabe

    1

    😕 😕 😕



  • #include <iostream>
    #include <boost/function/function1.hpp>
    
    int foo( int a )
     {
         return a;
    }
    
     int main( )
     {
         boost::function1< int, int > f = foo;
    
         std::cout << f( 1 ) << std::endl;
    }
    
    ------ Build started: Project: Boost_Test, Configuration: Release Win32 ------
    Compiling...
    main.cpp
    Linking...
    Generating code
    Finished generating code
    Embedding manifest...
    Build log was saved at "file://c:\Boost_Test\Release\BuildLog.htm"
    Test2 - 0 error(s), 0 warning(s)
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    


  • ricky schrieb:

    vielleicht so @Swordfish:

    #include <iostream>
    #include <boost/function/function1.hpp>
    
    int foo( int a )
    {
         return a;
    }
    
    int main( )
    {
         boost::function1< int, int> f;
    	 f = foo;
         std::cout << f( 1 ) << std::endl;
    }
    

    thx 👍

    @1310-Logik: Hä!? Selber Source:

    MSVC v7.1 (??) schrieb:

    main.cpp
    d:\root\projects\_Visual Studio\Kakauautomat\main.cpp(19) : error C2039: 'function' : Ist kein Element von 'boost'
    d:\root\projects\_Visual Studio\Kakauautomat\main.cpp(19) : error C2065: 'function' : nichtdeklarierter Bezeichner
    d:\root\projects\_Visual Studio\Kakauautomat\main.cpp(19) : error C2144: Syntaxfehler : 'int' sollte auf ')' folgen
    d:\root\projects\_Visual Studio\Kakauautomat\main.cpp(19) : error C2059: Syntaxfehler : ')'
    d:\root\projects\_Visual Studio\Kakauautomat\main.cpp(23) : error C2065: 'f' : nichtdeklarierter Bezeichner
    d:\root\projects\_Visual Studio\Kakauautomat\main.cpp(30) : error C2593: 'Operator <<' ist mehrdeutig

    Moment 'mal wie bekomm ich die Compilerversion 'raus?

    Greetz, Swordfish



  • bei mir so: Visual Studio 2005 Command Prompt starten dann folgendes eintippen:

    C:\>vbc
    Microsoft (R) Visual Basic Compiler version 8.0.50727.42
    for Microsoft (R) .NET Framework version 2.0.50727.42
    Copyright (c) Microsoft Corporation.  All rights reserved.
    

    cu



  • ricky schrieb:

    [...]
    Microsoft (R) Visual Basic Compiler version 8.0.50727.42
    [...]
    

    und was mach ich mit der Versionsnummer eines Visual Basic Compilers!?

    Greetz, Swordfish



  • Vielleicht dasselbe nochmal mit dem Visual C++ Compiler? 🙄



  • obs*g* naja ich glaub kaum das der vc compiler ne andere nummer hat;)
    ruf mal cl onder nmake auf...
    cu



  • @LordJaxom: kar, aber wie heißt der?

    Greetz, Swordfish



  • C:\Programme\Microsoft Visual Studio 8\VC\bin>nmake
    
    Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    NMAKE : fatal error U1064: MAKEFILE not found and no target specified
    Stop.
    

    oder?



  • fu*k:

    Microsoft (R) Program Maintenance Utility, Version 7.00.9466
    

    Damit hat sich das Thema mit boost::function wohl erledigt. Kann mir jemand verraten, ob man in ein MSVS 2002 .net einen späteren Compiler einbinden kann?

    Greetz, Swordfish



  • hast du boost mit "-sTOOLS=vc-7_0" compiliert?

    cu



  • Ne, aber jetzt compilier ich 'grad mit "-sTOOLS=vc7".

    Greetz, Swordfish



  • und gehts besser?



  • Hallo,

    Mircosoftprodukte machen nur ärger :D.

    MFG winexec*



  • winexec* schrieb:

    Hallo,

    Mircosoftprodukte machen nur ärger :D.

    MFG winexec*

    Nur wenn man nicht weiß wie man damit umgeht. Und das gilt nicht nur für Microsoft Programme.

    Für mich sieht es einfach so aus als hätte da jemand unteranderem die Include Verzeichnisse falsch gesetzt (edit: Oder überhaupt nicht) und http://www.boost.org/more/getting_started.html nicht gelesen.

    BR
    Vinzenz


Anmelden zum Antworten