public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23977] New: fails to resolve templated constructor
@ 2005-09-20 12:11 igodard at pacbell dot net
  2005-09-20 12:34 ` [Bug c++/23977] " giovannibajo at libero dot it
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2005-09-20 12:11 UTC (permalink / raw)
  To: gcc-bugs

template<typename T> class foo {
public: foo(T t) {}
};

int main() {
foo<int>(1);
foo(1);
}


gets you:

~/ootbc/members/src$ g++ foo.cc
foo.cc: In function `int main()':
foo.cc:7: error: missing template arguments before '(' token

-- 
           Summary: fails to resolve templated constructor
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23977


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

* [Bug c++/23977] fails to resolve templated constructor
  2005-09-20 12:11 [Bug c++/23977] New: fails to resolve templated constructor igodard at pacbell dot net
@ 2005-09-20 12:34 ` giovannibajo at libero dot it
  2005-09-20 12:45 ` igodard at pacbell dot net
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: giovannibajo at libero dot it @ 2005-09-20 12:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-09-20 12:34 -------
Yes, this is how C++ works. There is no template argument deduction from 
constructors.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23977


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

* [Bug c++/23977] fails to resolve templated constructor
  2005-09-20 12:11 [Bug c++/23977] New: fails to resolve templated constructor igodard at pacbell dot net
  2005-09-20 12:34 ` [Bug c++/23977] " giovannibajo at libero dot it
@ 2005-09-20 12:45 ` igodard at pacbell dot net
  2005-09-20 18:29 ` bangerth at dealii dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2005-09-20 12:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From igodard at pacbell dot net  2005-09-20 12:43 -------
Bummer. I wonder why? I suppose the workaround is an inline helper function
wrapping the constructor, plus a couple of calls on the copy constructor...

Ivan

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23977


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

* [Bug c++/23977] fails to resolve templated constructor
  2005-09-20 12:11 [Bug c++/23977] New: fails to resolve templated constructor igodard at pacbell dot net
  2005-09-20 12:34 ` [Bug c++/23977] " giovannibajo at libero dot it
  2005-09-20 12:45 ` igodard at pacbell dot net
@ 2005-09-20 18:29 ` bangerth at dealii dot org
  2005-09-20 18:36 ` igodard at pacbell dot net
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2005-09-20 18:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-09-20 18:28 -------
In particular, template arguments are _never_ deduced for types, only for 
functions. 
 
W. 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23977


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

* [Bug c++/23977] fails to resolve templated constructor
  2005-09-20 12:11 [Bug c++/23977] New: fails to resolve templated constructor igodard at pacbell dot net
                   ` (2 preceding siblings ...)
  2005-09-20 18:29 ` bangerth at dealii dot org
@ 2005-09-20 18:36 ` igodard at pacbell dot net
  2005-09-20 20:07 ` bangerth at dealii dot org
  2005-09-20 20:38 ` igodard at pacbell dot net
  5 siblings, 0 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2005-09-20 18:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From igodard at pacbell dot net  2005-09-20 18:36 -------
So a constructor counts as a type for deduction purposes? I'd always thought of
it as a function, albeit a peculiar kind of one. It's the parentheses I suppose :-)

Ivan

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23977


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

* [Bug c++/23977] fails to resolve templated constructor
  2005-09-20 12:11 [Bug c++/23977] New: fails to resolve templated constructor igodard at pacbell dot net
                   ` (3 preceding siblings ...)
  2005-09-20 18:36 ` igodard at pacbell dot net
@ 2005-09-20 20:07 ` bangerth at dealii dot org
  2005-09-20 20:38 ` igodard at pacbell dot net
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2005-09-20 20:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-09-20 20:07 -------
A constructor is a special function the name of which is that of the type 
to which it belongs. The type's name is that that includes template arguments. 
 
You could also say that the constructor is a function that is implicitly 
called upon creation of an object of a certain type. The name of the type 
is what you have to specify. 
 
That the constructor is not just another function is that in this case 
-------------- 
int f(int); 
template <typename T> int f(T); 
-------------- 
you can force the template be called even if the argument is an integer 
by calling f<int>(1). A similar trick doesn't work for constructors: 
-------------- 
struct S { 
  S(int); 
  template <typename T> S(T); 
}; 
 
S s(int);  // no way to get the template constructor called, whatever you do 
-------------- 
 
W. 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23977


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

* [Bug c++/23977] fails to resolve templated constructor
  2005-09-20 12:11 [Bug c++/23977] New: fails to resolve templated constructor igodard at pacbell dot net
                   ` (4 preceding siblings ...)
  2005-09-20 20:07 ` bangerth at dealii dot org
@ 2005-09-20 20:38 ` igodard at pacbell dot net
  5 siblings, 0 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2005-09-20 20:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From igodard at pacbell dot net  2005-09-20 20:38 -------
Many thanks for taking the time for the lengthy explanation. It is deeply
appreciated.

Ivan

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23977


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

end of thread, other threads:[~2005-09-20 20:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-20 12:11 [Bug c++/23977] New: fails to resolve templated constructor igodard at pacbell dot net
2005-09-20 12:34 ` [Bug c++/23977] " giovannibajo at libero dot it
2005-09-20 12:45 ` igodard at pacbell dot net
2005-09-20 18:29 ` bangerth at dealii dot org
2005-09-20 18:36 ` igodard at pacbell dot net
2005-09-20 20:07 ` bangerth at dealii dot org
2005-09-20 20:38 ` igodard at pacbell dot net

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).