im having trouble with this project i need to do
i was supplied with a bunch of code and told to finish it, i need to implement the has-a relationship between 4 different cpp files, but ill just paste 2 here cause once i figure 1 out i can do the rest
heres the picture of a UML image if it helps any:
http://webhost.bridgew.edu/jsantore/...2/Lab2-uml.jpg
im thinking its suppose to be something like this:
_something = new LeftBar();
but its not working
heres Flag.cpp, the file that i am suppose to implement the has-relationship with:
Code:
#include "Flag.h"
#include <iostream>
using namespace std;
Flag::Flag(){
/* This is called in all GTK applications.
We don't care about command line arguments so pass bogus ones*/
gtk_init (0, NULL);
_mainWin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
_box = gtk_hbox_new(TRUE, 0);
//add the has-a relationships here
//all your code should be above this line.
}
void Flag::initWindow(){
/* GtkWidget is the storage type for widgets */
/* create a new window */
// window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* When the window is given the "delete_event" signal (this is given
* by the window manager, usually by the "close" option, or on the
* titlebar), we ask it to call the delete_event () function
* as defined above. The data passed to the callback
* function is NULL and is ignored in the callback function. */
g_signal_connect (G_OBJECT (_mainWin), "delete_event",
G_CALLBACK (delete_event), NULL);
//add the container
gtk_container_add(GTK_CONTAINER (_mainWin), _box);
//show the container
gtk_widget_show (_box);
//change the window size to be something large enough
gtk_window_set_default_size(GTK_WINDOW(_mainWin), 600, 400);
/* show the window */
gtk_widget_show (_mainWin);
/* All GTK applications must have a gtk_main(). Control ends here
* and waits for an event to occur (like a key press or
* mouse event). */
gtk_main ();
}
//don't worry about this function, it just hides some of the ugly details of
//the underlying libraries that are being used.
void Flag::destroy( GtkWidget *widget,
gpointer data )
{
gtk_main_quit ();
}
//you do not need to worry about this method, it is written for you
//and simply hides some ugly details of the library we are using.
gboolean Flag::delete_event( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
/* If you return FALSE in the "delete_event" signal handler,
* GTK will emit the "destroy" signal. Returning TRUE means
* you don't want the window to be destroyed.
* This is useful for popping up 'are you sure you want to quit?'
* type dialogs. */
g_print ("delete event occurred\n");
/* Change TRUE to FALSE and the main window will be destroyed with
* a "delete_event". */
return FALSE;
}
int main()
{
Flag myFlag;
myFlag.initWindow();
}
and here is one of the cpp files that im suppose to have the has-a relationship from (LeftBar.cpp):
Code:
#include "LeftBar.h"
LeftBar::LeftBar(Flag* p){
_parent = p;
//now setup the underlying button functionality
_realBar = gtk_button_new();
//try some coloring
GdkColor leftC;
gdk_color_parse ("green", &leftC);
gtk_widget_modify_bg (_realBar, GTK_STATE_NORMAL, &leftC);
gtk_box_pack_start(GTK_BOX (_parent->getBox()), _realBar, TRUE, TRUE, 0);
gtk_widget_show(_realBar);
}
any help with this would be greatly appreciated, thanks in advance