Modulare Programmierung?!



  • Ich kapier echt gar nix!

    Drei Dateien:
    main.cpp

    #include "mywin.h"
    
    int main(int argc, char *argv[])
    {
    	Gtk::Main kit(argc, argv);
    	mywin testwin;
    	Gtk::Main::run(testwin);
    	return 0;
    }
    

    mywin.h

    #ifndef MYWIN_H
    #define MYWIN_H
    
    #include <gtkmm.h>
    
    class mywin : public Gtk::Window
    {
    	public:
    		mywin();
    
    	private:
    		Gtk::Button btn_test;
    		Gtk::VBox box_test;
    };
    
    #endif //ifndef MYWIN_H
    

    mywin.cpp

    #include "mywin.h"
    
    mywin::mywin()
    :	Gtk::Window(),
    	btn_test("TEST"),
    	box_test(true, 3)
    {
    	box_test.pack_start(btn_test);
    	add(box_test);
    }
    

    Witzfrage: Warum lässt sich das nicht bauen?

    Ausgabe:

    --------------------Configuration: test - Debug--------------------
    Compiling source file(s)...
    main.cpp
    In file included from main.cpp:1:
    mywin.h:17:24: warning: no newline at end of file
    main.cpp:9:2: warning: no newline at end of file
    mywin.h
    mywin.h:17:24: warning: no newline at end of file
    mywin.cpp
    In file included from mywin.cpp:1:
    mywin.h:17:24: warning: no newline at end of file
    mywin.cpp:10:2: warning: no newline at end of file
    Linking...
    C:\MinGWStudio\test\Debug\mywin.o: In function `ZN5mywinC2Ev':
    C:\MinGWStudio\test\mywin.cpp:4: multiple definition of `mywin::mywin()'
    C:\MinGWStudio\test\Debug\mywin.o:C:\MinGWStudio\test\mywin.cpp:4: first defined here
    C:\MinGWStudio\test\Debug\mywin.o: In function `ZN5mywinC1Ev':
    C:\MinGWStudio\test\mywin.cpp:4: multiple definition of `mywin::mywin()'
    C:\MinGWStudio\test\Debug\mywin.o:C:\MinGWStudio\test\mywin.cpp:4: first defined here
    collect2: ld returned 1 exit status
    
    test.exe - 4 error(s), 5 warning(s)
    

    Wenn ich alles in eine Datei packe, klappt es, also was mache ich falsch??



  • OMG bin ich duhm, ich hab die mywin.h unter Source Files gepackt anstatt Header Files.



  • modularer supernoob schrieb:

    OMG bin ich duhm, ich hab die mywin.h unter Source Files gepackt anstatt Header Files.

    Nochmal Danke Grober 😉


Anmelden zum Antworten