Thread: Re: [Dev-C++] Template member function (C++ obviously)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Hossein H. <ult...@em...> - 2003-07-27 15:35:33
|
Dear Paul,
> I hope anyone can help me, cause I'm starting to consider making the
> entire class a template, just to get rid of the linker error. I already
> switched from Visual C++ 6 to GCC because of one of the many bugs in
> VC++6, one of which is that it doesn't seem to understand/support
> template member functions.
Oh, yes! Member templatisation is one of the C++ features that the
nasty MSVC++6 doesn't supports. One of bewildering (known) bugs of it!
That's whilst member templatatisation is completely Standard-compliant,
and that's a shame, out of thousands, for MSVC++6!
Hmmm... One point more: I know that you told the error is engendered by
the linker, but consider the following peice of code which I site
directly from TC++PL:Spec (Section C.13.6):
class Memory{
public:
template<class T> T* get_new();
template<class T> void release(T&);
};
template<class Allocator> void f(Allocator& m)
{
int* p1 = m.get_new<int>();
//Syntax Error: int after less than operator
int* p2 = m.template get_new<int>();
//explicit qualification
//...
m.release(p1);
//template argument deduced: no explicit qualification needed
m.release(p2);
}
Are you sure that's not arisen because of forgetting the "template
qualifier?"
Regards,
--Hossein
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
|
|
From: Hossein H. <ult...@em...> - 2003-07-27 18:49:31
|
Hi Paul,
> So THAT's what I was doing wrong! *slaps forehead*
Ouch! Don't be that furious! It doesn't kill you if it goes wrong!
> I don't have much experience with template member functions yet, it's
> the first time I've used it in a real project. ...
You will obtain much experience just by experiment, Inshaallaah. Keep
on man!
> I called the function as
> follows (from within a member function of the Config class):
>
> ConfigParser cp;
> cp.Parse("somefile.conf", this, &Config::ConfigData);
>
> Which apparently should have been:
>
> ConfigParser cp;
> cp.Parse<Config>("somefile.conf", this, &Config::ConfigData);
Hmmm... It seems that it is not complete yet! Does it work on your
compiler? I will be astonished hearing that MSVC++6 can conclude the
template parameter using the return type. According the citation I
made from TC++PL:Spec, the flawless version should be like this:
cp.template Parse<Config>("somefile.conf", this, &Config::ConfigData);
Furthermore, it seems that something is going wrong here. According to
the Standard, Template parameters could not be deduced using the
return type, but the compilers are supposed to have the ability of
deducting the parameter type using the arguments. (This is explicitly
mentioned in TC++PL as well.) Now, does it have any problem with
deducting the template parameter type using the arguments? Could you
please rewrite the template function's skeleton?
> ... But anyway, thanks a lot! Now I can continue with my (much too
> time-consuming) little project :)
You'r welcome! There is no need to thanks! This is a friendly mailing-
list.
Regards,
--Hossein
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
|
|
From: P.D. v. Z. <pa...@my...> - 2003-07-29 20:50:46
|
:'(
It appears I'm still having problems... I thought they were gone. It
compiled fine once using
ConfigParser cp;
cp.Parse<Config>("blah", this, &Config::func);
But now I try to use it in some other class as well (the call to
ConfigParser::Parse), and I get linker errors for both the calls...
[Linker error] undefined reference to `void
ConfigParser::Parse<Language>(std::string const&, Language*, bool
(Language::*)(ConfigLine const&))'
[Linker error] undefined reference to `void
ConfigParser::Parse<Config>(std::string const&, Config*, bool
(Config::*)(ConfigLine const&))'
So once again I'm stumped. I tried your suggestion:
ConfigParser cp;
cp.template Parse<Config>("blah", this, &Config::func);
Which compiles as well, but still gives me linker errors. Maybe I
should've studied templates a bit more before trying to use them :P
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Hossein
Haeri
Sent: Sunday, July 27, 2003 8:49 PM
To: dev...@li...
Subject: RE: [Dev-C++] Template member function (C++ obviously)
Hi Paul,
> So THAT's what I was doing wrong! *slaps forehead*
Ouch! Don't be that furious! It doesn't kill you if it goes wrong!
> I don't have much experience with template member functions yet, it's
> the first time I've used it in a real project. ...
You will obtain much experience just by experiment, Inshaallaah. Keep on
man!
> I called the function as
> follows (from within a member function of the Config class):
>
> ConfigParser cp;
> cp.Parse("somefile.conf", this, &Config::ConfigData);
>
> Which apparently should have been:
>
> ConfigParser cp;
> cp.Parse<Config>("somefile.conf", this, &Config::ConfigData);
Hmmm... It seems that it is not complete yet! Does it work on your
compiler? I will be astonished hearing that MSVC++6 can conclude the
template parameter using the return type. According the citation I made
from TC++PL:Spec, the flawless version should be like this:
cp.template Parse<Config>("somefile.conf", this, &Config::ConfigData);
Furthermore, it seems that something is going wrong here. According to
the Standard, Template parameters could not be deduced using the return
type, but the compilers are supposed to have the ability of deducting
the parameter type using the arguments. (This is explicitly mentioned in
TC++PL as well.) Now, does it have any problem with deducting the
template parameter type using the arguments? Could you please rewrite
the template function's skeleton?
> ... But anyway, thanks a lot! Now I can continue with my (much too
> time-consuming) little project :)
You'r welcome! There is no need to thanks! This is a friendly mailing-
list.
Regards,
--Hossein
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job
search http://corp.mail.com/careers
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01
/01
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Tom C. <jat...@nt...> - 2003-07-29 22:33:36
|
Hi Paul, PDvZ> It appears I'm still having problems... I thought they were gone. TC > TC > Have you tried what I suggested on Sunday? PDvZ> PDvZ> Nope, haven't tried that yet. It's not quite clear to me how this PDvZ> would benefit anything, or how to implement it even :) PDvZ> PDvZ> How can I declare a class's member function outside of the class? PDvZ> The member function I'm having problems with isn't inlined, the PDvZ> implementation of it resides in a .cpp file... only the declaration is PDvZ> in the header file, so I think I shouldn't have any problems with PDvZ> separate definitions anyway... or am I wrong here? I know it sounds an unlikely workaround, but it solved a similar problem I had. Hopefully it will for you, too. You simply place the implementation of your member function, Parse, in a header file called, say, configparser_parse.h, instead of the CPP file you say it currently resides in, and then write '#include "configparser_parse.h"' at the bottom of the header file containing the class definition (but within its inclusion guard). With luck, the linker stops complaining. Here's a link to a page that provides a bit more information: http://www.comeaucomputing.com/techtalk/templates/#whylinkerror --Tom |
|
From: P.D. v. Z. <pa...@my...> - 2003-07-27 17:46:47
|
Hello again,
So THAT's what I was doing wrong! *slaps forehead*
I don't have much experience with template member functions yet, it's
the first time I've used it in a real project. I called the function as
follows (from within a member function of the Config class):
ConfigParser cp;
cp.Parse("somefile.conf", this, &Config::ConfigData);
Which apparently should have been:
ConfigParser cp;
cp.Parse<Config>("somefile.conf", this, &Config::ConfigData);
From the examples and help I found online I got the impression that this
template parameter was implicit... apparently not :) First I thought it
was something I did wrong with the body of the function (not specifying
things that I should, for instance), because almost everywhere the
samples only present inlined code.
But anyway, thanks a lot! Now I can continue with my (much too
time-consuming) little project :)
Greetings,
Paul
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Hossein
Haeri
Sent: Sunday, July 27, 2003 5:34 PM
To: dev...@li...
Subject: Re: [Dev-C++] Template member function (C++ obviously)
Dear Paul,
> I hope anyone can help me, cause I'm starting to consider making the
> entire class a template, just to get rid of the linker error. I
> already switched from Visual C++ 6 to GCC because of one of the many
> bugs in
> VC++6, one of which is that it doesn't seem to understand/support
> template member functions.
Oh, yes! Member templatisation is one of the C++ features that the nasty
MSVC++6 doesn't supports. One of bewildering (known) bugs of it! That's
whilst member templatatisation is completely Standard-compliant, and
that's a shame, out of thousands, for MSVC++6!
Hmmm... One point more: I know that you told the error is engendered by
the linker, but consider the following peice of code which I site
directly from TC++PL:Spec (Section C.13.6):
class Memory{
public:
template<class T> T* get_new();
template<class T> void release(T&);
};
template<class Allocator> void f(Allocator& m)
{
int* p1 = m.get_new<int>();
//Syntax Error: int after less than operator
int* p2 = m.template get_new<int>();
//explicit qualification
//...
m.release(p1);
//template argument deduced: no explicit qualification needed
m.release(p2);
}
Are you sure that's not arisen because of forgetting the "template
qualifier?"
Regards,
--Hossein
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job
search http://corp.mail.com/careers
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01
/01
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|