#Basic C++ Homework Help

14 messages · Page 1 of 1 (latest)

vague gull
#

Hello, I'm having trouble with my homework, I'm using Visual Studio to code. When I try to run my code, I keep getting error code E0392 at line 31 in Barn.cpp. I tried giving my code to ChatGPT to try and figure out the solution but it's not working. Here's my code:

keen otterBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

formal reef
#

Firstly: Never rely on ChatGPT

#

Secondly: what is the description for E0392

vague gull
#

Code E0392: member function "Barn::feedChickens" may not be redeclared outside its class

formal reef
#

you have misplaced a }

#

in barn.cpp

reef field
#

!f

keen otterBOT
#

Barn.h

#pragma once
#include <iostream>
#include <vector>

#include "Animal.h"
#include "Chicken.h"
#include "Cow.h"
#include "Pig.h"
using namespace std;

class Barn {
 private:
  vector<Chicken> coop;
  vector<Pig> pigPen;
  vector<Cow> cowPen;

 public:
  Barn();
  void feedChickens();
  void feedPigs();
  void feedCows();
};
QuietWisp
reef field
#

!f

keen otterBOT
#

Barn.cpp

#include "Barn.h"

// Constructor
Barn::Barn() {
  // Chicken- Hen Solo
  for (int i = 0; i < 1; i++) {
    string name = "Hen Solo";
    Chicken c(name, 5);
    coop.push_back(c);
  }

  // Cow- Daisy Daisy Daisy
  for (int i = 0; i < 1; i++) {
    string name = "Daisy Daisy Daisy";
    Cow c(name, 1411);
    cowPen.push_back(c);
  }

  // Pig- Hammy
  for (int i = 0; i < 1; i++) {
    string name = "Hammy";
    Pig c(name, 280);
    pigPen.push_back(c);
  }

  // Feed all chickens
  void Barn::feedChickens() {
    for (Chicken& chicken : coop) {
      chicken.eat();
    }
  }

  // Feed all cows
  void Barn::feedCows() {
    for (Cow& cow : cowPen) {
      cow.eat();
    }
  }

  // Feed all pigs
  void Barn::feedPigs() {
    for (Pig& pig : pigPen) {
      pig.eat();
    }
  }
}
QuietWisp
formal reef
#

the very last } should be moved to just before void Barn::feedChickens()

vague gull
#

It works now, thank you 🙂

#

!solved