Type_A to Type_B

The compiler encountered an illegal implicit conversion.

The ANSI C++ language differs from ANSI C in the treatment of void*. ANSI C allows an implicit conversion from a:

Pointer to void > to a pointer > to another object type (but not to a pointer to function type)

In C++, a void* cannot be assigned to an object of any type other than void* without an explicit cast.

The example below is legal ANSI C, but is not accepted in C++.

pour ce programme:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
ifstream * ouvrirFichierEntree( int argc, char **argv);
 
ifstream * ouvrirFichierEntree( int argc, char **argv)
{
   string fichierEntree;
  ifstream fichier;
  if(argc == 1)
  {			
     cout<<"Donnez le nom du fichier: ";
     cin>>fichierEntree;
  }
  else if(argc == 2 || argc == 3  )
  {
  	 fichierEntree = argv[1];
 
  }
  else 
  {
  	 cerr << "Erreur : vous n'avez pas respecte le nombre de parametre..." << endl;	
  	 return NULL ;
  }
 
	fichier.open(fichierEntree.c_str());
 
	if (!fichier)
    {
        cerr << "Erreur : impossible d'ouvrir le fichier en lecture..." << endl;
        return NULL;
    }
 
  return fichier;
}