Strings & Classes

Discussion in 'C++' started by Max_Payne_007, Nov 29, 2007.

  1. Max_Payne_007

    Max_Payne_007 New Member

    Joined:
    Oct 20, 2007
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Menu.h

    Code:
    
    #pragma once
    
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    class Menu
    {
    private:
    	string title;
    
    public:
    	Menu( void );
    	Menu( const Menu &unMenu );
    	~Menu( void );
    
    	void setTitle ( string title );
    	string getTitle() const;
    };
    

    Menu.cpp

    Code:
    #include "Menu.h"
    
    Menu::Menu(void)
    {
    	this->title = "Hello";
    }
    
    Menu::Menu(const Menu &unMenu)
    {
    	this->title = unMenu.title;
    
    }
    
    Menu::~Menu(void)
    {
    }
    
    ///////////////////////////////////////////////////
    
    void Menu::setTitle( string title )
    {
    	this->title = title;
    }
    
    string Menu::getTitle() const
    {
    	return ( this->title );
    }
    
    main.cpp

    Code:
    
    #include "Menu.h"
    
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    int main ()
    {
    	Menu m;
    
    	m.setTitle( "Spider Man 3" );
    	cout << m.getTitle();
    
    	system("PAUSE");
    	return 0;
    }
    
    I'm getting a problem when i put
    cout << m.getTitle();
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,355
    Likes Received:
    383
    Trophy Points:
    83
    What is the problem you are getting?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice