Re: Method should return list<>, instead returns BOOL, no error. Why not?



"Igor Tandetnik" wrote:
I have a class with a method that is declared to return a std::list<>
object, but instead it returns a BOOL value. However, no compiler
error is thrown. Why not?

Are you using VC6, by any chance? The code produces an error under VC7.1

BOOL is a typedef for int. std::list has a constructor that takes a single parameter of type size_t. This constructor is marked explicit in VC7.1, but I believe it was not in VC6 (I don't have it handy to check at the moment). If it's not marked explicit, this constructor can be used for type conversion. So what the compiler is doing is creating and returning a temporary instance of std::list, initialized by that one-argument constructor from the value of BOOL result.


Actually, VC6's `list' template has `explicit' specifier. Probably VC6 simply ignores it and creates an object anyway.

"list::list"
http://msdn.microsoft.com/library/en-us/vclang98/html/LIST_LISTCCLIST.asp

Alex

.



Relevant Pages

  • Re: Method should return list<>, instead returns BOOL, no error. Why not?
    ... However, no compiler ... BOOL is a typedef for int. ... This constructor is marked explicit in ... If it's not marked explicit, ...
    (microsoft.public.vc.stl)
  • Re: How to hide the close button??
    ... > to the full screen app. ... > dim canClose as bool ... > set it to false in the constructor ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Template return an error message
    ... //base template class ... Are you using VC6, by any chance? ... X<char, int> xii; ... Which part of "no appropriate default constructor" do you find difficult ...
    (microsoft.public.vc.language)
  • RE: Can a Windows Form return a value?
    ... > constructor, I call the method that runs the validation process. ... > possible that, once this process (which returns a bool) is finished, that it ... > value of checkRecordsLength() to Form_Main without having to add any ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to store the reference to a "bool" ?
    ... possibly modify that "bool" variable, ... So, after doing the code modifications you proposed, how do I update ... TCP_synch_client which is not the constructor? ... > public bool IsRunning ...
    (microsoft.public.dotnet.languages.csharp)

Loading