Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:32:01+00:00 2026-06-13T05:32:01+00:00

I have read about these two errors pretty extensively but despite all of my

  • 0

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:
Mystring.cpp

#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

Mystring.h

#pragma once
#include <string.h>
#include <iostream> 
#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& str);
    void insert (int pos1, const char* s);
    void erase (int pos, int n);
    int find(const MyString& str);
    int find(const char* s);
    int compare(const MyString& str);
    int compare(const char* s);
    const char* getStr() const;
    MyString::MyString(const MyString &that);
    MyString & operator=(const char chars[]);
    MyString & operator=(const MyString& str);

};

#endif

MystringDerived.h

#pragma once
#include "MyString.cpp"
#ifndef MYSTRINGDERIVED_H
#define MYSTRINGDERIVED_H
class MyStringDerived :
    public MyString
{
public:

    MyStringDerived(char chars[]);
    bool operator>(MyString rhs);
    bool operator>=(MyString rhs);
    bool operator<(MyString rhs);
    bool operator<=(MyString rhs);
    bool operator==(MyString rhs);
    bool operator!=(MyString rhs);
    bool operator+(MyString rhs);
    bool operator[](MyString rhs);
    MyStringDerived(void);
    ~MyStringDerived(void);
};

#endif

MyStringDerived.cpp

    #pragma once
#include "MyStringDerived.h"
#ifndef MYSTRINGDERIVED_CPP
#define MYSTRINGDERIVED_CPP

MyStringDerived::MyStringDerived(char * const)
{
}


MyStringDerived::~MyStringDerived(void)
{
}
#endif

and the errors I get

    1>test.obj : error LNK2005: "public: int __thiscall MyString::length(void)" (?length@MyString@@QAEHXZ) already defined in MyString.obj
1>test.obj : error LNK2005: "public: void __thiscall MyString::resize(int,char)" (?resize@MyString@@QAEXHD@Z) already defined in MyString.obj
1>C:\Users\Arthur\Documents\Visual Studio 2012\Projects\Project1\Debug\Project2.exe : fatal error LNK1169: one or more multiply defined symbols found

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.

Thanks!

Forgot to include test.cpp. it’s as simple as this at the moment :

MyStringDerived m = “test”; cout<< m.getStr(); getchar(); return
0;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:32:02+00:00Added an answer on June 13, 2026 at 5:32 am

    I think the problem is on line 2 of MyStringDerived.h. You are including MyString.cpp when you should be including MyString.h

    [update]

    The way you have it coded, all the definitions of MyString.cpp are compiled into the MyString.obj file – this is good and as it should be. Unfortunately, because of your #include, all of the definitions of MyString.cpp also appear in MyDerivedString.obj

    To really understand why this is a problem, you need to take some time and study the difference between a declaration and a definition – just google “c++ declaration vs definition”. Here is an article that may be helpful. http://www.cprogramming.com/declare_vs_define.html

    Anything that is “declared” can be included again and again into a program without any harm. Anything that is defined must appear once and only once across all object files that are linked into the application.

    This leads to the following general guidelines:

    A header file (.h) must only contain declarations. It must not contain any definitions. Only .cpp files can contain definitions. Then you must make sure to never to #include a .cpp file. Its the easiest way to ensure that you will never have duplicate definitions at link time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read about continuency parser and dependency parser. but confused which could be
I have read about a lot of people having problems with the browser not
I have read about application object in android site but I couldn't understand. What
A have read about A* as well as D* and similar, and i'm not
I have the following two errors when using XMLReader. 1) Warning: XMLReader::read() [xmlreader.read]: MyXML.xml:43102:
first of all, i like to say that i have read the other two
I have read about session fixation and from what I understand it forces a
I have read about LDAP on wikipedia and I kind of understand what it
I have read about the push technologies recently. Using it real-time data streaming is
I have read about dynamically loading your class files when needed in a function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.