🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #308826

[c++] strchr jako argument templata się nie kompiluje

#308826
From: Wojciech Muła
Date: Thu, 06 Oct 2016 17:00
38 lines
2302 bytes
GCC 4.9.2, taki kod:

---
#include <cstring>

const char* my_strchr(const char* s, int c) {
    return s + c;
}

template <typename STRLEN>
const char* foo(STRLEN strchr_fun, const char* s, int c) {
    return strchr_fun(s, c);
}

int main() {
    foo(my_strchr, "hello world", '?');
    foo(std::strchr, "hello world", '?');
}
---

$ gcc -std=c++14 bug.cpp

bug.cpp: In function ‘int main()’:
bug.cpp:14:40: error: no matching function for call to ‘foo(<unresolved overloaded function type>, const char [12], char)’
     foo(std::strchr, "hello world", '?');
                                        ^
bug.cpp:14:40: note: candidate is:
bug.cpp:8:13: note: template<class STRLEN> const char* foo(STRLEN, const char*, int)
 const char* foo(STRLEN strchr_fun, const char* s, int c) {
             ^
bug.cpp:8:13: note:   template argument deduction/substitution failed:
bug.cpp:14:40: note:   couldn't deduce template parameter ‘STRLEN’
     foo(std::strchr, "hello world", '?');

Po prostu nie rozumiem. Ten strchr to jest jakieś makro,
czy co?

w.
Technical Details
Message-ID: <355b5d0e-c1fe-431d-bf40-adf894da42b0@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!o19no629617ito.0!news-out.google.com!203ni1844itk.0!nntp.google.com!o19no629599ito.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Received: by 10.107.170.202 with SMTP id g71mr3952620ioj.76.1475773205664;        Thu, 06 Oct 2016 10:00:05 -0700 (PDT)
X-Received: by 10.36.20.10 with SMTP id 10mr1846534itg.2.1475773205632; Thu, 06 Oct 2016 10:00:05 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!o19no629617ito.0!news-out.google.com!203ni1844itk.0!nntp.google.com!o19no629599ito.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Thu, 6 Oct 2016 10:00:04 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=37.47.134.255; posting-account=VFwkXwoAAADdT4-lLKRZrMYkTjizGoyn
NNTP-Posting-Host: 37.47.134.255
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <355b5d0e-c1fe-431d-bf40-adf894da42b0@googlegroups.com>
Subject: [c++] strchr jako argument templata się nie
 kompiluje
From: Wojciech Muła <wojciech_mula@poczta.onet.pl>
Injection-Date: Thu, 06 Oct 2016 17:00:05 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit