Start New Discussion within our Software Development Community

I am getting 3 error messages:
-cannot convert from 'const char [2]' to 'char [10]'
2messages of: 'char secretType::setName(char)' : overloaded member function not found in 'secretType'

#include <iostream>
#include <cstring>
using namespace std;

class secretType
{private:
    char name[10];        *error message here
    int age, weight;
    double height;
public: 
    char setName ();
    int setAge ();
    int setWeight ();
    double setHeight ();
    const char getName ();          //accessor function
    const int getAge ();            //accessor function
    const int getWeight ();         //accessor function
    const double getHeight ();      //accessor function
    secretType ()                   //default constructor
    {name = " "; age = 0; weight = 0; height = 0;}
};
/********** 10 Member function definitions ***********/

char secretType::setName(char name)         
{n = name;
}

char secretType::getName(char name)
{cin.getName(name);
cin.ignore();       //ignore the '\n' in the input buffer
cout << "The name you entered is:\n";

//Loop through the array printing each character 
for(int index = 0; name[index] != '\0'; index++)
{cout << name[index];}
return 0;

}

error 1:

/*you are writting*/
secretType () //default constructor
{name = " "; age = 0; weight = 0; height = 0;}
/*remember your 'name' var was like: char name[10]*/
/*but you are assigning it a value which is an address to a string of size 2 i.e. " ". one space and the \0 character.*/
/*This is not a way how u can copy one string to other*/

use strcpy()


error 2:

/*your prototype is*/
char setName ();

/*but u are defining another member as:*/
char secretType::getName(char name)

check the difference yourself.

And anyways, I guess you are trying to set the name which is a string and not a character, so your prototype should be like

void setName(const char *name);
This article has been dead for over six months. Start a new discussion instead.