Error in assignment char :
structplusclass.cpp: In constructor ‘Soldado::Soldado(char, unsigned int, char, char, char)’: structplusclass.cpp:25:27: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive] strcpy(mTodos.modelo, mol); ^ In file included from /usr/include/c++/5/cstring:42:0, from structplusclass.cpp:2: /usr/include/string.h:125:14: note: initializing argument 2 of ‘char* strcpy(char*, const char*)’ extern char *strcpy (char *__restrict __dest, const char *__restrict __src) ^ structplusclass.cpp:27:29: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive] strcpy(mTodos.material, mat); ^ In file included from /usr/include/c++/5/cstring:42:0, from structplusclass.cpp:2: /usr/include/string.h:125:14: note: initializing argument 2 of ‘char* strcpy(char*, const char*)’ extern char *strcpy (char *__restrict __dest, const char *__restrict __src) ^ structplusclass.cpp:28:18: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive] strcpy(mNome, ns); Code:
#include <iostream> #include <cstring> #define SIZE 20 using namespace std; struct faca { char modelo[SIZE]; unsigned int peso; char material[15]; }; class Soldado { public: Soldado (char ns, unsigned int p, char mat, char arm, char mol); ~Soldado (); void Imprime(); protected: faca mTodos; char mNome[SIZE]; char mArmapri[SIZE]; }; Soldado::Soldado (char ns, unsigned int p, char mat, char arm, char mol) { strcpy(mTodos.modelo, mol); mTodos.peso = p; strcpy(mTodos.material, mat); strcpy(mNome, ns); strcpy(mArmapri, arm); } void Soldado::Imprime () { cout << "Soldado : " << mNome << ", " << "firearm : " << mArmapri << endl; cout << endl << " Faca : " << mTodos.modelo << ", " << "lenght : " << mTodos.peso << ", " << "Material : " << mTodos.material << endl; } Soldado::~Soldado () { mTodos.peso = 0; } int main() { char names1[SIZE], fire[SIZE]; char names2[SIZE], mat[15]; unsigned int eight; cout << "nome Soldado, nome arma de fogo " << endl; cin >> names1 >> fire; cout << "modelo faca e material " << endl; cin >> mat >> names2; cout << "peso" << endl; cin >> eight; Soldado brazil(names1, eight, mat, fire, names2); brazil.Imprime(); return 0; }
const char*,char[]andchar? It seems it is right time to read some good book for beginners.