Note that there are some explanatory texts on larger screens.

plurals
  1. POLNK2005 and LNK1169 on debug objects
    primarykey
    data
    text
    <p>I have read about these two errors pretty extensively but despite all of my efforts I can not see the problem here. I have absolutely flooded my code with header guards to see if that will help, with no change in the result. here are each of the files: <strong>Mystring.cpp</strong></p> <pre><code>#pragma once #include "MyString.h" #ifndef MYSTRING_CPP #define MYSTRING_CPP using namespace std; MyString::MyString(char chars[]){ str = (char*) malloc(strlen(chars)); str = chars; } //etc, other methods as defined in header file #endif </code></pre> <p><strong>Mystring.h</strong></p> <pre><code>#pragma once #include &lt;string.h&gt; #include &lt;iostream&gt; #ifndef MYSTRING_H #define MYSTRING_H using namespace std; class MyString { protected: char * str; public: ~MyString(); MyString(char chars[]); MyString(const char chars[]); MyString(); int length(); void resize(int n, char c); void clear(); bool empty(); void insert(int pos1, const MyString&amp; str); void insert (int pos1, const char* s); void erase (int pos, int n); int find(const MyString&amp; str); int find(const char* s); int compare(const MyString&amp; str); int compare(const char* s); const char* getStr() const; MyString::MyString(const MyString &amp;that); MyString &amp; operator=(const char chars[]); MyString &amp; operator=(const MyString&amp; str); }; #endif </code></pre> <p><strong>MystringDerived.h</strong></p> <pre><code>#pragma once #include "MyString.cpp" #ifndef MYSTRINGDERIVED_H #define MYSTRINGDERIVED_H class MyStringDerived : public MyString { public: MyStringDerived(char chars[]); bool operator&gt;(MyString rhs); bool operator&gt;=(MyString rhs); bool operator&lt;(MyString rhs); bool operator&lt;=(MyString rhs); bool operator==(MyString rhs); bool operator!=(MyString rhs); bool operator+(MyString rhs); bool operator[](MyString rhs); MyStringDerived(void); ~MyStringDerived(void); }; #endif </code></pre> <p><strong>MyStringDerived.cpp</strong></p> <pre><code> #pragma once #include "MyStringDerived.h" #ifndef MYSTRINGDERIVED_CPP #define MYSTRINGDERIVED_CPP MyStringDerived::MyStringDerived(char * const) { } MyStringDerived::~MyStringDerived(void) { } #endif </code></pre> <p>and the errors I get</p> <pre><code> 1&gt;test.obj : error LNK2005: "public: int __thiscall MyString::length(void)" (?length@MyString@@QAEHXZ) already defined in MyString.obj 1&gt;test.obj : error LNK2005: "public: void __thiscall MyString::resize(int,char)" (?resize@MyString@@QAEXHD@Z) already defined in MyString.obj 1&gt;C:\Users\Arthur\Documents\Visual Studio 2012\Projects\Project1\Debug\Project2.exe : fatal error LNK1169: one or more multiply defined symbols found </code></pre> <p>There are hundreds of error lines that all look like this. With the way I organized my includes, I definitely don't see how I might be ending up with multiple copies being included. Is there something else I'm missing? Any insights are appreciated. This is homework (obviously), so I definitely want to actually understand the problem when I'm done here. No one I've shown it to has caught what i'm doing wrong.</p> <p>Thanks!</p> <p>Forgot to include test.cpp. it's as simple as this at the moment :</p> <blockquote> <p>MyStringDerived m = "test"; cout&lt;&lt; m.getStr(); getchar(); return 0;</p> </blockquote>
    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.
    1. This table or related slice is empty.
    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