Using Set and Get

+1 John Shaw · December 8, 2014
Hi all,

I am want to use the set / get functions, outside of main.cpp and **.h file
(in other words placed in a separate source file)

I'm trying to clean up my code, so as the class(s)  contain only "int, string **, double ....
and all the functions are separated out..

I managed to get the  '  DisplayStats ' to work ok....then  I tried to d the same with Race_Name...

Code::Blocks said No !!

for the life of me I can't seem to get my code to work...

Any help greatly received.



the class in h file :

class Vessel_Race
{
public:
int x;
// ****************************************************************************************
  string GetRace_Name ( ) { return RACE_TYPE;}
  void SetRace_Name ( string x) { RACE_TYPE=x;}                    // Determine Race Type
// ****************************************************************************************
protected:

private:
 string RACE_TYPE;  // Get/SetRace_Name

};

class Vessel_Construction:public Vessel_Race,public Vessel_Hull,public Vessel_Engines
{
public:void DisplayStats(); // Display Ship Statts
Vessel_Construction();
protected:
};



Source File

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include "Ship.h"
using namespace std;


// *********************** Vessel_Construction:isplayStats() ****************************
Vessel_Construction::Vessel_Construction()
{
}

void Vessel_Construction:isplayStats()

{
// *********************** Vessel_Construction:isplayStats() ****************************
    cout<<"\n\n\t-------Ship Statts-------";
    cout<<"\n\n\tNAME: "<<setw(15)<<GetRace_Name();

}
// _____________________ Vessel_Construction:isplayStats() ___________________________________

 

Post a Reply

Replies

Oldest  Newest  Rating
0 Mathias Frits Rørvik · December 8, 2014
Firstly, use code tags.
Secondly, what errors are you getting?
0 John Shaw · December 8, 2014
Hi,

Thank you so much for the reply, (slightly embarrassing though)  I've managed to correct the mistake.

I had missed:-


doing this in the  Ship.cpp   file

#include <cstdlib>
#include <iostream>
#include <iomanip>

#include "Ship.h"

using namespace std;

Vessel_Hull::Vessel_Hull(){}

// *********************** Vessel_Construction::Brdg_Hull_Intg() ****************************
   int Vessel_Hull::GetBrdg_Hull_Intg()

     { return BRIDGE_HULL_INTEGRITY;}
// *********************** Vessel_Construction::Brdg_Hull_Intg() ****************************  



and this in the h. File


class Vessel_Hull

{
public:


int x;
Vessel_Hull();

// ****************************************************************************************
    int GetBrdg_Hull_Intg(); // { return BRIDGE_HULL_INTEGRITY;}
    void SetBrdg_Hull_Intg(int x) {BRIDGE_HULL_INTEGRITY=x;}
// ****************************************************************************************

protected:

private:

int BRIDGE_HULL_INTEGRITY;
};

Now i can use the SetBrdg_Hull_Intg();

From Main.cpp, and the value changes accordingly in the output.

Thank's again for your time.
  • 1

C++

103,727 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator