MESSAGE
DATE | 2011-05-26 |
FROM | Ruben Safir
|
SUBJECT | Subject: [ruben@mrbrklyn.com: Re: [NYLXS - HANGOUT] C++ Workshop - New
|
----- Forwarded message from Ruben Safir -----
Date: Wed, 25 May 2011 17:16:18 -0400 From: Ruben Safir To: Ruben Safir Cc: nylug-talk-at-nylug.org Subject: Re: [NYLXS - HANGOUT] C++ Workshop - New Webservices with OKWS - Tuesday Night User-Agent: Mutt/1.5.20 (2009-06-14)
On Wed, May 25, 2011 at 05:10:40PM -0400, Ruben Safir wrote: > n Monday 23 May 2011 16:37:36 Ruben Safir wrote: > > I'm having trouble understanding why my program is making a change in > > the argument type of my template class function > > > > template < class T > > > void List::find_value(T val) > > ... > > I then pass int search_val to method > > chainlist::List::find_value(T) > > where T = stats::Distribution (where T is an int) on this line: > > > > dump->find_value(search_val); > > > > and that's where the weirdness happens. I have a type mismatch > > since > > I'm sending by value an integer instead of a stats::Distribution > > < Out of curiosity, is this typcastable? e.g.: > > dump->find_value((stats::Distribution)search_val);> > > That is exactly the type that the function takes in the context of the > calling, class. T is an int. The issue winds up being that of > implicit conversion which happens if there is a stats::Distirbution > single argument constructor. For this to happen, the Template argument > needs to be specifically defined, which it is in this case since it was > defined in the class. > > > > << [function for reference: void List::find_value(T val) ] > > I think this is a case where the compiler needs help, because > find_value() is > looking for a templated generic value, so the compiler doesn't > know that it > can't send in a simple integer. The whole purpose of using > templates is to > keep the type abstract, so I'm not sure how you'd solve this > within the > function header. >> > > As it turns out, this is an explicit rule. If T is not defined, the > implicit conversion can not happen a`nd it is considered, "Can not be > deduced". > > o > > > << > I've been trying to read your C++ code, but I've been finding > it difficult; > the stream of templated objects... wow. However in the middle > of trying to > read things that I can parse, I noticed the following: > >> > > Well, it's an excersize in templates. Your familiar with the rules for > vector<> and list<> because they are part of the standard template > libray. My chainlist::List seems to be pretty decent at this point, but > the syntax is unknown unless you pour over the code *List<>->cursor() > returns a chainlist::Node class object. It contains a pointer to a > value of type T and a pointer to the Next Node > > Things get exciting when T is its own class. > > << float mean_list( ) > ... > while(tallies->cursor() != tallies->endd() ){ > ... > if(dump->cursor() != NULL) > ... > } > ... > if(dump->cursor() != 0) > > If dump->cursor() is a pointer, then compare it with NULL, not 0. > >> > > There is a lot of debate on this issue. Strausoup strongly urges 0, > but frankly, dealing with nulls in C++ is a PIA, and even moreso now > with the new standard which blows a warning at you if you assign NULL > to an int type variable. > > << Even if > this works, I'd choose one test and try to stick to it for > readability > reasons. > >> > > Ruben > > > -- Chris > > -- > Chris Knadle > Chris.Knadle at coredump.us > >
From usenet
I'm getting this warning that appears in the 4.6 GCC compiler that didn't happen before.
the warning is
/home/ruben/cplus/link_list_template_mysql/stats.h|45 col 42| warning: converting to non-pointer type .int. from NULL [-Wconversion-null]
if comes from a default constructor
Distribution():freq(NULL), occurances(0){};
occurances is an int type, and the compiler is complaining about occurances(0)
it goes away when I change it to
Distribution():freq(NULL){ occurances = 0;
};
but then it complains about freq which is of type T in a template
Ruben
> > -- > http://www.mrbrklyn.com - Interesting Stuff > http://www.nylxs.com - Leadership Development in Free Software > > So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 > > http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 > > "Yeah - I write Free Software...so SUE ME" > > "The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society." > > "> I'm an engineer. I choose the best tool for the job, politics be damned.< > You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one." > > ? Copyright for the Digital Millennium
-- http://www.mrbrklyn.com - Interesting Stuff http://www.nylxs.com - Leadership Development in Free Software
So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998
http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
"Yeah - I write Free Software...so SUE ME"
"The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society."
"> I'm an engineer. I choose the best tool for the job, politics be damned.< You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one."
? Copyright for the Digital Millennium
----- End forwarded message -----
|
|