Note that there are some explanatory texts on larger screens.

plurals
  1. POPrograms compiles in g++ but exits with linker errors in gcc
    primarykey
    data
    text
    <p>I'm trying out the <a href="https://stackoverflow.com/questions/1162401/is-it-possible-to-access-values-of-non-type-template-parameters-in-specialized-te/1162910#1162910">solution</a> to a <a href="https://stackoverflow.com/questions/1162401/is-it-possible-to-access-values-of-non-type-template-parameters-in-specialized-te">question about specialized template classes</a>. </p> <p>This code with a compiles fine in g++, but throws up linker errors when compiled with gcc. What's the cause of these errors ? </p> <pre><code>$ g++ traits2.cpp $ gcc traits2.cpp /tmp/ccI7CNCY.o: In function `__static_initialization_and_destruction_0(int, int)': traits2.cpp:(.text+0x36): undefined reference to `std::ios_base::Init::Init()' traits2.cpp:(.text+0x3b): undefined reference to `std::ios_base::Init::~Init()' /tmp/ccI7CNCY.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status </code></pre> <p>The traits2.ccp file contains the aforementioned <a href="https://stackoverflow.com/questions/1162401/is-it-possible-to-access-values-of-non-type-template-parameters-in-specialized-te/1162910#1162910">solution</a> with an emtpy main() function:</p> <pre><code>#include &lt;iostream&gt; using namespace std; // A default Traits class has no information template&lt;class T&gt; struct Traits { }; // A convenient way to get the Traits of the type of a given value without // having to explicitly write out the type template&lt;typename T&gt; Traits&lt;T&gt; GetTraits(const T&amp;) { return Traits&lt;T&gt;(); } template &lt;int major, int minor&gt; struct A { void f() { cout &lt;&lt; major &lt;&lt; endl; } }; // Specialisation of the traits for any A&lt;int, int&gt; template&lt;int N1, int N2&gt; struct Traits&lt;A&lt;N1, N2&gt; &gt; { enum { major = N1, minor = N2 }; }; template &lt;&gt; struct A&lt;4,0&gt; { void f() { cout &lt;&lt; "Specialized:" &lt;&lt; GetTraits(*this).major &lt;&lt; endl; } }; int main(int argc, char * argv[] ) { /* A&lt;4,0&gt; p; A&lt;1,2&gt; p2; p.f(); p2.f(); */ return 1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload