#include <iostream>
usingnamespace std;
#include "randomclassheader.h"
#include <string.h>
#include <cstdlib>
int main()
{
char firstname[50];
char secondname[50];
char eyecolour[50];
int age;
float weight;
Person(firstname, secondname, eyecolour, age, weight);
cout << "Please enter your first name:" << endl;
cin >> firstname;
cout << "Please enter your second name:";
cin >> secondname;
cout << "Please enter your eye colour:";
cin >> eyecolour;
cout << "Please enter your age:";
cin >> age;
cout << "Please enter your weight:";
cin >> weight;
cout << "This is your first name: " << firstname;
cout << endl << endl << endl << endl << "This is the name of the first person in the class: " <<endl;
return 0;
}
||=== Random test class, Debug ===|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp||In constructor ‘Person::Person(char*, char*, char*, int, float)’:|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|11|error: ‘firstname’ was not declared in this scope|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|12|error: returning a value from a constructor|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp||In member function ‘void Person::createFirstName(char*)’:|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|20|error: ‘firstname’ was not declared in this scope|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|21|error: return-statement with a value, in function returning 'void'|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp||In member function ‘void Person::createSecondName(char*)’:|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|27|error: ‘secondname’ was not declared in this scope|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|28|error: return-statement with a value, in function returning 'void'|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|32|error: prototype for ‘void Person::createWeight(float*)’ does not match any in class ‘Person’|
/home/rej3kt/Desktop/random test class/Random test class/randomclassheader.h|32|error: candidate is: void Person::createWeight(float)|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|39|error: prototype for ‘void Person::createAge(char*)’ does not match any in class ‘Person’|
/home/rej3kt/Desktop/random test class/Random test class/randomclassheader.h|26|error: candidate is: void Person::createAge(int)|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp||In member function ‘void Person::createEyeColoure(char*)’:|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|48|error: ‘eyecolour’ was not declared in this scope|
/home/rej3kt/Desktop/random test class/Random test class/randomtestclass.cpp|49|error: return-statement with a value, in function returning 'void'|
||=== Build finished: 12 errors, 0 warnings ===|
I've been at this for ages so a quick response would be awesome, also if you could respond in layman's terms I'd appreciate it! Thanks -Rob
Just say if you need me to post my header file as well
Person::Person(char firstName[], char secondName[] ,char EyeColour[] ,int Age, float weight)
{
strcpy(firstname, firstName); // <--- 'firstname' is obviously not declared in your class
return firstName; // <--- It's a constructor you can't return anything
}
error: ‘firstname’ was not declared in this scope|
Maybe a case mismatch, or something. Post your header for more info.
error: returning a value from a constructor|
error: return-statement with a value, in function returning 'void'|
What the error says. Constructors and void functions can't return anything. You can have an empty return statement in a void function though.
error: prototype for ‘void Person::createWeight(float*)’ does not match any in class ‘Person’|
etc.
In c++ function is defined not only by its name, but also return type and arguments. Therefore void Person::createWeight(float*) is not the same as void Person::createWeight(float)
I understand now void doesn't return anything it's just copying the string from the variable personName to the member in the class called theName, so what does char* Person::getName() do? This is my working version btw