I have the need to pass a string to a class. Am I missing something, as the .cpp file of the class throws an error on the type with this code:
Inside Main.cpp I have the function call inside a file read... this is a continuation from a previous program... here is the code snippet that would be useful:
main.cpp:
Animal.h:
Animal.cpp:
Again, I need to pass the string species into the Animal class.
Inside Main.cpp I have the function call inside a file read... this is a continuation from a previous program... here is the code snippet that would be useful:
main.cpp:
if (id == "Animal")
{
//Making the Animal1 object
Animal Animal1;
//Data reading & manipulation
data >> age;
age = age * 365;
data >> energy;
data >> weight;
data >> species; //*****string that needs to be passed to the function, pulls from input.txt file*****
//Inserts pointer to object to the back of this list
animalList.push_back(new Animal(age,weight,energy,species));
}
Animal.h:
class Animal
{
public:
int age, weight;
float energy;
string species;
Animal();
~Animal();
Animal(int, int, float, string);
};
Animal.cpp:
#include "Animal.h"
#include <iostream>
using namespace std;
Animal::Animal()
{
}
Animal::~Animal()
{
}
Animal::Animal(int a, int w, float e, string s)
{
age = a;
weight = w;
energy = e;
species = s
}
Again, I need to pass the string species into the Animal class.