delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/07/14/17:19:23

From: "Rafal 'Raf256' Maj" <rafal AT raf256 DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: ambignous ?
Date: 14 Jul 2002 20:31:35 GMT
Organization: news.onet.pl
Lines: 60
Sender: raf256 AT poczta DOT onet DOT pl@rafal.joint.eu.org
Message-ID: <Xns924BE48E29A41raf256com@213.180.128.20>
NNTP-Posting-Host: rafal.joint.eu.org
Mime-Version: 1.0
X-Trace: news.onet.pl 1026678695 26804 62.233.182.179 (14 Jul 2002 20:31:35 GMT)
X-Complaints-To: abuse AT onet DOT pl
NNTP-Posting-Date: 14 Jul 2002 20:31:35 GMT
User-Agent: Xnews/5.03.24
X-Complains-To: admin AT raf256 DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,
I have a little problem

-8<-----------------------------------------------
#include <iostream.h>
#include <fstream.h>

class coWidth {
  public : int m; coWidth(int a) : m(a) {  }
};

ofstream& operator<<(ofstream &s, coWidth cmd) {
  return s;
}

int main() {
  ofstream s;
  s<<' ';
  return 0;
}
-8<-----------------------------------------------

This source generates error :

tmp.cpp(14) Error: choosing `std::basic_ostream<char, _Traits>&
   std::operator<<(std::basic_ostream<char, _Traits>&, char) [with _Traits 
=
   std::char_traits<char>]' over `std::ofstream& operator<<(std::ofstream&,
   coWidth)'
tmp.cpp(14) Error: because worst conversion for the former is better than 
worst
   conversion for the latter
There were some errors

I wanted to use class coWidth only manual s<<coWidth(5) and NOT to use it 
automaticly s<<' ';

one of work arounds colud be to change :
  coWidth(int a,char z)

what is the best work around ?

==================

making the only constructor private :

class coWidth {
  private :
    int m;
    coWidth(int a) : m(a) {  }
};

didn't help neither... why ?
i'm using GCC 3.04



-- 
Rafał 'Raf256' Maj

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019