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 8475425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:53:20+00:00 2026-06-10T17:53:20+00:00

I am new to C++. So I am creating a program which gathers then

  • 0

I am new to C++.

So I am creating a program which gathers then displays information about book etc. First, I want to learn little more about code I am doing but I am unfamiliar with c++ error codes.

I have created 2 classes Book and Publisher where each contains its own constructors and methods. After I tried to make my program including all classes and methods that I am given in my class diagram I came to halt when I received error saying:

1>Publisher.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getPublisherInfo(void)" (?getPublisherInfo@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in Book.obj
1>Publisher.obj : error LNK2005: "void __cdecl setAddress(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setAddress@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in Book.obj
1>Publisher.obj : error LNK2005: "void __cdecl setCity(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setCity@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in Book.obj
1>Publisher.obj : error LNK2005: "void __cdecl setName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?setName@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in Book.obj
1>C:\Users\pc\Desktop\School\ITS 340\Labs\Lab 1\Lab 1\Debug\Lab 1.exe : fatal error LNK1169: one or more multiply defined symbols found

This is my Publisher.cpp file:

#include <iostream>
using namespace std;

class Publisher
{
    public: 
        Publisher();
        Publisher(string name, string address, string city);
        string getPublisherInfo();
        void setName(string name);
        void setAddress(string address);
        void setCity(string city);

    private:
        string name;
        string address;
        string city;
};

Publisher::Publisher()
{
}

Publisher::Publisher(string name, string address, string city)
{
}

string getPublisherInfo()
{
    return 0;
}

void setName(string name)
{
}

void setAddress(string address)
{
}

void setCity(string city)
{
}

How can I avoid this error?

  • 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-10T17:53:22+00:00Added an answer on June 10, 2026 at 5:53 pm

    You are breaking the one definition rule. You need to declare classes and functions in header files, protect them with include guards , and only put implementations or definitions of functions and class member functions in your .cpp files.

    For example:

    Foo.h:

    #ifndef FOO_H_
    #define FOO_H_
    class Foo {
      Foo();
      void foo() const;
    };
    #endif
    

    Foo.cpp:

    #include "Foo.h"
    Foo::Foo() { .... }
    void Foo::foo() const { .... }
    

    main.cpp

    #include "Foo.h"
    int main()
    {
      Foo f;
      f.foo();
    }
    

    This is completely independent of OOP. You would have to do the same with free functions.

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

Sidebar

Related Questions

In my android program an Activity calls a new surface view class, which then
I'm creating an android application for someone that gathers information about his clients and
I'm creating a new shorcut within and update of my program on the Start
I'm new to creating installers using Visual Studio, and was wondering about the Global
I am new to creating work item types in TFS and want to create
I need UNION two tables with creating new field, where 1 for first table,
I am creating a program that is effectively an sprite creator. I'm very new
I am creating a program for my exam in programming on first semester of
I am writing a small program which needs to create a new file with
I'm creating this simple program which would save me alot of time, but I'm

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.