🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: variadic templates - rozwijanie argumentów, błąd kompilacji

#310388
From: Maciek Godek
Date: Fri, 16 Sep 2022 23:09
52 lines
3206 bytes
środa, 14 września 2022 o 18:34:23 UTC+2 Maciek napisał(a):
> kod poniższy działa: 
> 
> void print() { 
> std::cout << "IN FUNCTION " << __func__ << std::endl; 
> std::cout << "ENDING ..." << std::endl; 
> return; 
> } 
> 
> template<typename T, typename ... A> 
> auto print(T a, A... args) -> void { 
> std::cout << "IN FUNCTION " << __func__ << std::endl; 
> std::cout << a << std::endl; 
> print(args ...); 
> } 
> 
> Natomiast w przypadku szablonu: 
> 
> template<typename T, typename ... Types> 
> class T_Operators_tests { 
> public: 
> T_Operators_tests() {} 
> ~T_Operators_tests() {} 
> 
> void print() { 
> std::cout << "IN FUNCTION " << __func__ << std::endl; 
> std::cout << "ENDING ..." << std::endl; 
> return; 
> } 
> void print(T var1, Types... var2) 
> { 
> std::cout << var1 << std::endl; 
> 
> this->print(var2...); 
> } 
> }; 
> 
> kompilator nie chce rozwinąć funkcji i nie pasuje mu liczba argumentów 
> 
> Severity Code Description Project File Line Suppression State 
> Error C2661 'T_Operators_tests<int,int,int,int>::print': no overloaded function takes 3 arguments TestCpp1 operators_learn.hpp 37 
> 
> Na czym polega mój błąd ?

Cóż, nie za bardzo rozumiem C++, ale jeśli bym miał zgadywać,
to wygląda mi na to, że problem jest taki, że w tym drugim przypadku
każde ukonkretnienie szablonu powoduje powstanie nowej klasy,
w której metoda print przyjmuje konkretną liczbę argumentów.

Natomiast w ciele metody "print" próbujesz użyć (poprzez this)
metodę print, która będzie raczej przynależeć do innej klasy
(tzn. ukonkretnionej dla mniejszej liczby argumentów).
Technical Details
Message-ID: <b18725ba-4286-43f5-b72f-5ecfa09d8908n@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!news.quux.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
References: <28531d26-4cfe-4805-99ba-96dcbf0e18e4n@googlegroups.com>

Show Full Headers
Complete Article Headers
X-Received: by 2002:a0c:8107:0:b0:496:a715:dc8c with SMTP id 7-20020a0c8107000000b00496a715dc8cmr6308977qvc.96.1663369769496;        Fri, 16 Sep 2022 16:09:29 -0700 (PDT)
X-Received: by 2002:a05:622a:8e:b0:35b:acbe:cb48 with SMTP id o14-20020a05622a008e00b0035bacbecb48mr6769807qtw.390.1663369769307; Fri, 16 Sep 2022 16:09:29 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!news.quux.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Fri, 16 Sep 2022 16:09:29 -0700 (PDT)
In-Reply-To: <28531d26-4cfe-4805-99ba-96dcbf0e18e4n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=188.47.116.89; posting-account=f7iIKQoAAAAkDKpUafc-4IXhmRAzdB5r
NNTP-Posting-Host: 188.47.116.89
References: <28531d26-4cfe-4805-99ba-96dcbf0e18e4n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b18725ba-4286-43f5-b72f-5ecfa09d8908n@googlegroups.com>
Subject: Re: variadic templates - rozwijanie
 argumentów, błąd kompilacji
From: Maciek Godek <godek.maciek@gmail.com>
Injection-Date: Fri, 16 Sep 2022 23:09:29 +0000
X-Received-Bytes: 3167
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit