<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kevin Godby &#187; gcc</title>
	<atom:link href="http://kevin.godby.org/tag/gcc/feed/" rel="self" type="application/rss+xml" />
	<link>http://kevin.godby.org</link>
	<description>My Weblog</description>
	<lastBuildDate>Mon, 17 May 2010 17:40:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Explanations of a few g++ compiler error messages</title>
		<link>http://kevin.godby.org/2008/09/18/explanations-of-a-few-g-compiler-error-messages/</link>
		<comments>http://kevin.godby.org/2008/09/18/explanations-of-a-few-g-compiler-error-messages/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 06:16:11 +0000</pubDate>
		<dc:creator>Kevin Godby</dc:creator>
				<category><![CDATA[school]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[g++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[message]]></category>

		<guid isPermaLink="false">http://kevin.godby.org/?p=189</guid>
		<description><![CDATA[I was going through some old notebooks tonight and found a page where I&#8217;d noted some of the error messages that g++ gave me during some early C++ coursework. I took the time to write nice explanations of the error messages: what they mean and how to fix them. I figured that someone else may [...]]]></description>
			<content:encoded><![CDATA[<p>I was going through some old notebooks tonight and found a page where I&#8217;d noted some of the error messages that g++ gave me during some early C++ coursework.  I took the time to write nice explanations of the error messages: what they mean and how to fix them.  I figured that someone else may find them useful, so I&#8217;ll post them here.  If you have good explanations of other g++ compiler error messages that you&#8217;ve encountered, feel free to leave a comment.</p>
<h3>error: cannot declare member function ‘static void C::f()’ to have static linkage</h3>
<p>You have put <code>static</code> not only on the member function declaration, but on the definition too. Remove <code>static</code> from the definition.</p>
<pre>
class C
{
    static void f();
};

void C::f() // &larr; there should be no <strong>static</strong> here
{
    // ...
}
</pre>
<h3>error: static member function &lsquo;static void C::f()&rsquo; cannot have cv-qualifier</h3>
<p>You can&#8217;t have a const static member function. Remove the <code>const</code> qualifier from the static member function.</p>
<p>The <code>const</code> qualifier means that the implicit <code>this*</code> will not be modified by the member function. However, <code>this*</code> is not passed to static member functions&mdash;only non-static member functions. Therefore, there is no <code>this*</code> to be declared const.</p>
<h3>undefined reference to vtable for C::f()</h3>
<p>Check for the following:</p>
<ul>
<li>You declared a <code>virtual</code> method in a base class but did not implement it. Also, make sure your build system is including the <tt>.o</tt> or <tt>.cpp</tt> file that defines the method.</li>
<li>If you have a static member variable, you must define it in your <tt>.cpp</tt> file too:
<pre>
// c.h

class C
{
    static std::vector&lt;std::string&gt; databases;
};

// c.cpp

#include "c.h"
std::vector&lt;std::string&gt; C::databases; // &larr; define it in your .cpp file as well!
</pre>
</li>
</ul>
<h3>B is an inaccessible base of C</h3>
<p><code>B</code> is a base class for <code>C</code>. In class <code>A</code>, you&#8217;re trying to access <code>B</code> but you&#8217;ve likely forgotten to mark the inheritance public:</p>
<pre>
// c.h

class B { }; // a base class

class C : B // &larr; forgot to specify <strong>public</strong> B!
{
    public:
        static B* create(); // trying to return the parent class type,
                            // but it can't be accessed (it's private by default)
};
</pre>
<p>Also, the public qualifier isn&#8217;t distributive. So:</p>
<pre>
class C : public B1, B2 { }; // B2 is <strong>private</strong> here
</pre>
<p>is not the same as:</p>
<pre>
class C : public B1, public B2 { };
</pre>
]]></content:encoded>
			<wfw:commentRss>http://kevin.godby.org/2008/09/18/explanations-of-a-few-g-compiler-error-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.728 seconds -->

