CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jun 2007
    Posts
    9

    [RESOLVED] Derived class: hot to get mad!!!!

    Hi all! I'm trying to get this (i must admit: stupid) program to function properly..but i can't. This is what i get:

    Code:
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    persona.h: In constructor ‘Persona::Persona(char, char, int)’:
    persona.h:13: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:13: error:   initializing argument 1 of ‘size_t strlen(const char*)’
    persona.h:13: error: invalid conversion from ‘char*’ to ‘char’
    persona.h:14: error: invalid conversion from ‘char’ to ‘char*’
    persona.h:14: error:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
    persona.h:14: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:14: error:   initializing argument 2 of ‘char* strcpy(char*, const char*)’
    persona.h: In destructor ‘Persona::~Persona()’:
    persona.h:20: error: type ‘char’ argument given to ‘delete’, expected pointer
    studente.h: At global scope:
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    studente.h: In constructor ‘Studente::Studente(char, int, char, int, int, char)’:
    studente.h:11: error: invalid conversion from ‘const char’ to ‘const char*’
    studente.h:11: error:   initializing argument 1 of ‘size_t strlen(const char*)’
    studente.h:12: error: invalid conversion from ‘const char’ to ‘const char*’
    studente.h:12: error:   initializing argument 2 of ‘char* strcpy(char*, const char*)’
    borsista.h: At global scope:
    borsista.h:9: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    borsista.h:9: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    borsista.h:9: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    personamain.cpp: In function ‘int main()’:
    personamain.cpp:7: error: invalid conversion from ‘const char*’ to ‘char’
    personamain.cpp:7: error:   initializing argument 1 of ‘Persona::Persona(char, char, int)’
    personamain.cpp:7: error: invalid conversion from ‘const char*’ to ‘char’
    personamain.cpp:7: error:   initializing argument 2 of ‘Persona::Persona(char, char, int)’
    personamain.cpp:8: error: invalid conversion from ‘const char*’ to ‘char’
    personamain.cpp:8: error:   initializing argument 1 of ‘Studente::Studente(char, int, char, int, int, char)’
    personamain.cpp:8: error: invalid conversion from ‘const char*’ to ‘int’
    personamain.cpp:8: error:   initializing argument 2 of ‘Studente::Studente(char, int, char, int, int, char)’
    personamain.cpp:8: error: invalid conversion from ‘const char*’ to ‘char’
    personamain.cpp:8: error:   initializing argument 6 of ‘Studente::Studente(char, int, char, int, int, char)’
    personamain.cpp:9: error: invalid conversion from ‘const char*’ to ‘char’
    personamain.cpp:9: error:   initializing argument 1 of ‘Borsista::Borsista(char, int, char, int, int, char, long int)’
    personamain.cpp:9: error: invalid conversion from ‘const char*’ to ‘int’
    personamain.cpp:9: error:   initializing argument 2 of ‘Borsista::Borsista(char, int, char, int, int, char, long int)’
    personamain.cpp:9: error: invalid conversion from ‘const char*’ to ‘char’
    personamain.cpp:9: error:   initializing argument 6 of ‘Borsista::Borsista(char, int, char, int, int, char, long int)’
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    persona.h: In constructor ‘Persona::Persona(char, char, int)’:
    persona.h:13: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:13: error:   initializing argument 1 of ‘size_t strlen(const char*)’
    persona.h:13: error: invalid conversion from ‘char*’ to ‘char’
    persona.h:14: error: invalid conversion from ‘char’ to ‘char*’
    persona.h:14: error:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
    persona.h:14: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:14: error:   initializing argument 2 of ‘char* strcpy(char*, const char*)’
    persona.h: In destructor ‘Persona::~Persona()’:
    persona.h:20: error: type ‘char’ argument given to ‘delete’, expected pointer
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    persona.h: In constructor ‘Persona::Persona(char, char, int)’:
    persona.h:13: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:13: error:   initializing argument 1 of ‘size_t strlen(const char*)’
    persona.h:13: error: invalid conversion from ‘char*’ to ‘char’
    persona.h:14: error: invalid conversion from ‘char’ to ‘char*’
    persona.h:14: error:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
    persona.h:14: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:14: error:   initializing argument 2 of ‘char* strcpy(char*, const char*)’
    persona.h: In destructor ‘Persona::~Persona()’:
    persona.h:20: error: type ‘char’ argument given to ‘delete’, expected pointer
    studente.h: At global scope:
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    studente.h: In constructor ‘Studente::Studente(char, int, char, int, int, char)’:
    studente.h:11: error: invalid conversion from ‘const char’ to ‘const char*’
    studente.h:11: error:   initializing argument 1 of ‘size_t strlen(const char*)’
    studente.h:12: error: invalid conversion from ‘const char’ to ‘const char*’
    studente.h:12: error:   initializing argument 2 of ‘char* strcpy(char*, const char*)’
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    persona.h:12: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    persona.h: In constructor ‘Persona::Persona(char, char, int)’:
    persona.h:13: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:13: error:   initializing argument 1 of ‘size_t strlen(const char*)’
    persona.h:13: error: invalid conversion from ‘char*’ to ‘char’
    persona.h:14: error: invalid conversion from ‘char’ to ‘char*’
    persona.h:14: error:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
    persona.h:14: error: invalid conversion from ‘const char’ to ‘const char*’
    persona.h:14: error:   initializing argument 2 of ‘char* strcpy(char*, const char*)’
    persona.h: In destructor ‘Persona::~Persona()’:
    persona.h:20: error: type ‘char’ argument given to ‘delete’, expected pointer
    studente.h: At global scope:
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    studente.h:10: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    studente.h: In constructor ‘Studente::Studente(char, int, char, int, int, char)’:
    studente.h:11: error: invalid conversion from ‘const char’ to ‘const char*’
    studente.h:11: error:   initializing argument 1 of ‘size_t strlen(const char*)’
    studente.h:12: error: invalid conversion from ‘const char’ to ‘const char*’
    studente.h:12: error:   initializing argument 2 of ‘char* strcpy(char*, const char*)’
    borsista.h: At global scope:
    borsista.h:9: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    borsista.h:9: error: default argument for parameter of type ‘char’ has type ‘const char [2]’
    borsista.h:9: error: default argument for parameter of type ‘char’ has type ‘const char [1]’
    The program files are:

    persona.h
    Code:
    //file: persona.h
    
    #ifndef PERSONA_h
    #define PERSONA_h
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    class Persona{
    	public:
    		Persona(const char NAME="", char SEX="M",int AGE=0){
    			nome = new char[strlen(NAME)+1];
    			strcpy(nome,NAME);
    			sesso = SEX;
    			eta = AGE;
    		}
    		~Persona() {
    			cout << "distruttore Persona invocato\n";
    			delete[] nome;
    		}
    		void chisei() {
    			cout << "sono una Persona di nome " << nome << " ho " << eta << " anni e sono " << sesso << endl;
    		}
    	protected:
    		char *nome;
    		char sesso;
    		int eta;
    };
    
    
    #endif
    studente.h
    Code:
    //file studente.h 
    
    #ifndef STUDENTE_H
    #define STUDENTE_H
    
    #include "persona.h"
    
    class Studente:public Persona{
    	public:
    		Studente(const char NAME="", int SEX=0, char AGE="M", int EXAM=0, int MATR=1111111,const char FACULTY=""):Persona(NAME,SEX,AGE){
    		facolta = new char[strlen(FACULTY)+1];
    		strcpy(facolta,FACULTY);
    		esami = EXAM;
    		matricola = MATR;
    		}
    		~Studente() {
    			cout << "Dealloco Studente...\n";
    			delete []facolta;
    		}
    		void chisei(){
    			Persona::chisei();
    			cout << "In più sono uno studente di " << facolta << " matricola " << matricola << " e " << esami << " esami\n";
    		}
    	protected:
    		int esami;
    		int matricola;
    		char *facolta;
    };
    
    
    #endif
    borsista.h
    Code:
    //file borsista.h
    
    #ifndef BORSISTA_H
    #define BORSISTA_H
    #include "studente.h"
    
    class Borsista:public Studente{
    	public:
    		Borsista(const char NAME="", int SEX=0, char AGE="M", int EXAM=0, int MATR=1111111,const char FACULTY="", long BAG=0):Studente(NAME,FACULTY,AGE,SEX,EXAM,MATR){
    			borsa = BAG;
    		}
    		~Borsista(){
    			cout << "dealloco borsista\n";
    		}
    		void chisei(){
    			Studente::chisei();
    			cout << " e sono anche un borsista, con una borsa di " << borsa << endl;
    		}
    	protected:
    		long borsa;
    };
    
    
    
    #endif
    personamain.cpp
    Code:
    #include <iostream>
    #include "borsista.h"
    
    using namespace std;
    
    int main() {
    	Persona primo("Giorgio","M",15);
    	Studente secondo("Valeria","F",20,5,121232,"Storia");
    	Borsista terzo("giustino","M",22,9,123424,"Ingegneria");
    	primo.chisei();
    	secondo.chisei();
    	terzo.chisei();
    	return 0;
    }
    Please help me!!!!! :AAAAAAAAAAAAA
    Last edited by jubstuff; June 14th, 2007 at 06:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured