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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:21:58+00:00 2026-06-09T22:21:58+00:00

I have three files. file 1 This has the class definition and all the

  • 0

I have three files.

file 1
This has the class definition and all the methods in the class are also defined here

file 2
The object of the above class is instantiated here

file 3
Here I want to call one of the methods using the object created in file 2

I am trying to do above thing is because I want the code to be modular. Is there a better way to do this? Can you post any other solution that you may have?

  • 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-09T22:21:59+00:00Added an answer on June 9, 2026 at 10:21 pm

    Put your definition into an header file (usually .h):

    //header File1.h
    class File1
    {
        void Foo();
    };
    

    Include definition and implement it in another file (usualy .cpp)

    //File1.cpp
    #include "File1.h"
    
    File1::Foo()
    {
    
    }
    

    Then include the header with the definitions where you want to use

    //File2.cpp
    
    #include "File1.h"
    
    File1 file1;
    file1.Foo();
    

    Remember that the 2 translation units must be linked together.

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

Sidebar

Related Questions

I have a open file dialog with three filters: QString fileName = QFileDialog::getOpenFileName( this,
If I have three files index.php file.php and fns.php First example (it works): index.php
I have three files, a main .cpp file: #include <stdio.h> #include myClass.h int main()
I have three files: movie.h (header); movie.cpp (implementation file); lab9.cpp (driver file using movie
This has been stumping me for a bit. I have a Class written in
I have a fairly large Excel file. In this file there is a column
I have this iPad app using Storyboard. There are some file that are marked
I have a text file that looks like this: value1 value2 value3 There are
I have this code to download a file, but on sourceforge.net sever there is
I have three file in a directory: a.html : <html> a </html> b.html :

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.