0

i have these set and get methods declared in my main cpp file

void issuesofRelevance::setApproach(int Approach) {

approach = Approach;

}

int issuesofRelevance::getApproach() {

return approach;

}
void issuesofRelevance::setSignifiance(int Significance) {

significance = Significance;

}

int issuesofRelevance::getSignificance() {

return significance;

}

The following H file is attatched in which I call the setMethods in its constructor.

class  issuesofRelevance
{
  public:
     std::vector<std::string> issueName;
     int significance;
     int approach;
     std::vector<std::string> newList;

    issuesofRelevance(std::vector<std::string> issueName, int significance, int approach){

        issueName = issueName;
        significance = significance;
        approach = approach;
        setApproach(15);
        setSignifiance(15);

    }

     issuesofRelevance();

     void setIssues();
     std::string getIssues();


      void setApproach(int x);
      void setSignifiance(int);

      int getApproach();
      int getSignificance();
      };

I call the get functions in main int() as such

cout << object.getApproach();
cout << object.getSignificance();

However, when i go to run the code in the console I get no output when it should return the values of 10 and 15. Im unsure as to why this is occuring

Thankyou.

my full main as requested

int main(int argc, char* argv[]) { //takes in n, number of electorates, and m, the number of campagian days 

issuesofRelevance newIssues(newIssues.issueName, newIssues.significance, newIssues.approach);
return 0;
Party party;
Person person;
Electrorates electorate;
string numberofElectoratesAsString = argv[1]; //number of electorates taking as a argument 
string DaysOfElectionAsString = argv[2]; //takes in argument 2

int numberofElectorates =  std::stoi(numberofElectoratesAsString);
int DaysOfElection =  std::stoi(DaysOfElectionAsString );


cout << "Number of electorates: " << electorate.assignID(electorate.numberofElectorates(numberofElectorates));
cout << "Stance: " << person.setinitalStance(numberofElectorates, DaysOfElection) << endl;
newIssues.setIssues(); 
cout<<newIssues.getApproach()<< " "<<newIssues.getSignificance();



return 0;
}

default constructor

issuesofRelevance::issuesofRelevance(){
}
Bao Ling
  • 69
  • 7
  • if you use getter/setter, associate member can be private. – Jarod42 May 27 '20 at 07:35
  • better to have const getter. – Jarod42 May 27 '20 at 07:36
  • 1
    `approach = approach;` is noop. (self assign argement), and member is set afterward with `setApproach(15)` making parameter useless. – Jarod42 May 27 '20 at 07:39
  • Please try expanding your code into a small program we could compile and try for ourselves. As it stands, it is not clear (to me) why you're seeing no output when streaming an `int` to `std::cout` - regardless of where that `int` came from. – einpoklum May 27 '20 at 07:39
  • 1
    There is also nothing in that code which sets any value to `10` (the constructor that accepts multiple arguments sets values to `15`, and no definition is provided for the constructor that accepts no argument). So, even if output was produced, the information you haven't provided means that nobody can guess why you expect a value of `10`. Read up on providing a [mcve] - if you don't, you are denying people information that they would need if they are to have any chance of helping you. – Peter May 27 '20 at 07:44
  • @AdrianMole ive added all this to the end of my question if you'd like to look at it – Bao Ling May 27 '20 at 08:09
  • You have an unwanted `return 0;` statement as the second line of your `main` function! There are also a number of other errors: like what do you expect the passed values to be in your first line of that `main`? – Adrian Mole May 27 '20 at 08:11
  • id expected them to be the name of the issue, and the approach and signifiance being 10 and 10 – Bao Ling May 27 '20 at 08:14
  • @AdrianMole I am trying to learn – Bao Ling May 27 '20 at 08:17
  • @AdrianMole I am pleased to say that with your help i have done it! – Bao Ling May 27 '20 at 08:22
  • @BaoLing OK, well I am happy to have helped. But trying to initialize a class object using members of that object as parameters is really not going to achieve anything useful. – Adrian Mole May 27 '20 at 08:25

0 Answers0