public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Can you use a function reference passed in a template argument?
@ 2023-11-09 20:46 Arthur Schwarz
  2023-11-09 21:02 ` Thomas Bleher
  2023-11-09 21:11 ` Jonathan Wakely
  0 siblings, 2 replies; 8+ messages in thread
From: Arthur Schwarz @ 2023-11-09 20:46 UTC (permalink / raw)
  To: gcc-help


Is there any way to use a function passed as an argument to a template 
(example below)? Couldn't the existence of the referenced function be 
established durint instantiation (Stack<some class> obj)? I realize that 
just doing analysis of the template that the existence of a referenced 
function can't be determined, but during instantiation it can be validated.

As a nit, the repeated instances of "../header/" in the error message is 
an annoyance.

Diagnostic message and code given below.

thanks
art

../header/../header/../header/../header/Stack.h: In member function 
‘std::string Stack<T>::toString()’:
../header/../header/../header/../header/Stack.h:184:46: error: expected 
primary-expression before ‘.’ token
   184 |       str << setw(3) << s.size() << ": " << T.toString();
       |                                              ^

# include <iomanip>
# include <sstream>

using namespace std;
template <class T>
class Stack {
    string toString() {
       stringstream str;
       str << setw(3) << s.size() << ": " << T.toString();
       return str.str();
    };
};


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-09 22:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 20:46 Can you use a function reference passed in a template argument? Arthur Schwarz
2023-11-09 21:02 ` Thomas Bleher
2023-11-09 21:07   ` Arthur Schwarz
2023-11-09 21:11 ` Jonathan Wakely
2023-11-09 21:24   ` Arthur Schwarz
2023-11-09 21:58     ` Jonathan Wakely
2023-11-09 22:00       ` Jonathan Wakely
2023-11-09 22:10         ` Arthur Schwarz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).