This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problems with conversion function : got the error


Hi,

regarding my problem (see below), I got the error --- a definition of a variable
was understood as the declaration of a function (this ugly thing):

I used

Compilation<gpc_delphi_transfer, Environment_wwwrun, both_outputs, unchanged_source_file, transfer_source_name>
    C(unchanged_source_file::Source_file_data(program_full_name), transfer_source_name::Executable_file_data(base_compilation));


which should have declared a variable of type

 Compilation<gpc_delphi_transfer, Environment_wwwrun, both_outputs, unchanged_source_file, transfer_source_name>, 

using a constructor of the template class Compilation with two parameters, which are of type 

unchanged_source_file::Source_file_data

and

transfer_source_name::Executable_file_data

and where temporary values of these types are created (program_full_name and base_compilation are two variables).

HOWEVER, the compiler thought, I declared a function called C, with return value of type

 Compilation<gpc_delphi_transfer, Environment_wwwrun, both_outputs, unchanged_source_file, transfer_source_name>,

and with two parameters, the first of type

unchanged_source_file::Source_file_data

and the *parameter* called program_full_name, and the second of type

transfer_source_name::Executable_file_data

and the *parameter* base_compilation.

Sigh. I have seen this in Scott Meyers book, and as I remember, there the trick was to use
brackets around the parameter list for C. This doesn't work here, but one can put brackets around
the first argument, and then it works:

	  Compilation<gpc_delphi_transfer, Environment_wwwrun, both_outputs, unchanged_source_file, transfer_source_name>
	    C((unchanged_source_file::Source_file_data(program_full_name)), transfer_source_name::Executable_file_data(base_compilation));
	  Pid = C;

So there was no problem with the conversion function (at least in this case). I hope the above
discussion might be helpful for others who might stumble over similar problems.

Oliver

P.S. Since I registered yesterday evening for the list, I didn't get any mail from the
list --- hope it works.

> Hi,
> 
> nearly every time I'm using a conversion function it does not work, so I basically
> stopped using conversion functions, but this evening I'm pretty determined --- I have
> to know what's going on!
> 
> Unfortunately, I have never been able to reproduce the error with a small example, so
> here's the error message I get (I'm using gcc version 3.0.4 (SuSE)):
> 
> 
> submission.cpp: In function `CgiHandling::Transfer_codes transfer(const
>    CgiHandling::ValueMap&, const std::string&)':
> submission.cpp:257: no matching function for call to
>    `SystemHandling::PidType::PidType(AutomatedCompilation::Compilation<AutomatedCompilation::gpc_delphi_transfer,
>    AutomatedCompilation::Environment_wwwrun,
>    AutomatedCompilation::both_outputs,
>    AutomatedCompilation::unchanged_source_file,
>    AutomatedCompilation::transfer_source_name> (&)(std::basic_string<char,
>    std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
>    std::char_traits<char>, std::allocator<char> >))'
> SystemHandling.hpp:317: candidates
>    are: SystemHandling::PidType::PidType(const SystemHandling::PidType&)
> SystemHandling.hpp:319:
>                   SystemHandling::PidType::PidType()
> 
> 
> the offending line 257 (in submission.cpp) is:
> 
> Pid = (PidType) C;
> 
> (where I get the same error for other forms:
> Pid = C; Pid = PidType(C);),
> 
> where we have the declaration
> 
> PidType Pid;
> 
> and
> 
> Compilation
>   <gpc_delphi_transfer, Environment_wwwrun, both_outputs, unchanged_source_file, transfer_source_name>
>   C (unchanged_source_file::Source_file_data(program_full_name), transfer_source_name::Executable_file_data(base_compilation));
> 
> (sorry for the mess, but I don't know what's wrong here, so I included everything)
> 
> while in the class template Compilation a conversion function is declared:
> 
>  template
>   < class Compiler, class Environment, class Compiler_Output, class Source, class Executable >
>   class Compilation : public Compiler, public Environment, public Compiler_Output, public Source, public Executable {
>   public :
>     operator SystemHandling::PidType() const { return Pid; }
> 
>   private :
> 
>     SystemHandling::PidType Pid;
>   };
> 
> One sees, that the compiler, when seeing
> Pid = (PidType) C;
> only looks out for a constructor for class PidType (there is an explicitely defined default constructor,
> while the copy assignment operator is defined implicitly), but ignores the conversion function 
> defined in class Compilation. WHY???
> 
> I would be glad for any help!
> 
> Oliver



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]