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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:12:48+00:00 2026-05-27T19:12:48+00:00

I have 4 classes: Server.cpp Logger.cpp Util.cpp Crypto.cpp The class Server use the object

  • 0

I have 4 classes:
Server.cpp Logger.cpp Util.cpp Crypto.cpp

The class Server use the object Util.
The program works fine, but now I need to use the object Util also in the class Logger.
But when I put in the code #include “Util.cpp” g++ give me an error because I cannot call again the object.
Eclipse told me about the “redefinition” and “previous declaration” of class Util.

How can I solve this?

  • 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-05-27T19:12:48+00:00Added an answer on May 27, 2026 at 7:12 pm

    You should not include the source cpp files in to another cpp file.
    This basically violates the One Definition Rule resulting in redefinition errors.

    Include the header file which has the definiition of Util class in whichever class you want to create its objects.

    Basically, Your code should be organized in this fashion(exception: Templatized code):

    Util.h ———–> Contains Definition of class Util acts as Interface
    Util.cpp ———–> Contains Implementation of class Util acts as Implementation

    Here on whenever you want to create an object of class Util in any of the cpp files you include Util.h in that cpp file so the compiler knows the definition of class Util.

    For ex:
    Server.cpp wants to create an object of Util then your Server.cpp should include Util.h as:

    #include "Util.h"
    

    Also, don’t forget to add Include guards to your header files.

    If the usage of Util by another source/header file is limited to creating a pointer to Util then you do not need to include the header file, You only need to Forward declare the Util class.

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

Sidebar

Related Questions

I have written a simple program that use some classes and procol buffers. These
I have two classes, a server and some clients. The server class make a
I have these classes: Form1.cs Server.cs Now when I do in Server.cs form1.startCapture(C:\\test.mp4); Then
I have classes that are needed in both my web service and my server.
I have the same classes on my server and on my web service. I
I'm trying to connect to a AS400 server using the .net classes. I have
Consider a situation. I have an in-proc COM server that contains two COM classes.
If I have classes of Type A and B: public class A { public
I have two classes X and Y, like this: class X implements Serializable {
I have an existing class library with all the classes to communicate with my

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.