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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:10:58+00:00 2026-06-12T09:10:58+00:00

Possible Duplicate: Regarding C++ Include another class i am new and would like to

  • 0

Possible Duplicate:
Regarding C++ Include another class

i am new and would like to learn more about how do i split my C++ file into .h and .cpp

this is my File2.cpp

#include <iostream>
#include <string>

using namespace std;

class ClassTwo
{
private:
string myType;
public:
void setType(string);
string getType();
};


void ClassTwo::setType(string sType)
{
myType = sType;
}

void ClassTwo::getType(float fVal)
{
return myType;
}

I want split it into 2 files, which is .h and .cpp
how do i split this as its a class, with private & public.

And I would like to use ClassTwo in File1.cpp(another cpp file)

How do i link it so i can use it at ClassTwo

Thanks for help.

  • 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-12T09:10:58+00:00Added an answer on June 12, 2026 at 9:10 am

    //File2.h

    #include <iostream>
    #include <string>
    
    
    class ClassTwo
    {
    private:
       std::string myType;
    public:
       void setType(std::string);
       std::string getType();
    }; 
    

    //File2.cpp

    #include"File2.h"
    
    void ClassTwo::setType(std::string sType)
    {
        myType = sType;
    }
    
    std::string ClassTwo::getType()
    {
        return myType;
    } 
    

    //File1.cpp

    #include "File1.h"   //If one exists
    #include "File2.h"
    
    
    int main()
    {
        ClassTwo obj;
        return 0;
    }
    

    On a side note, I already explained this in very much detail on your previous question here.
    Did you even read it?

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

Sidebar

Related Questions

Possible Duplicate: C/C++, can you #include a file into a string literal? I have
Possible Duplicate: Do you know tool building tree of include files in project\file? Currently
Possible Duplicate: Calling null on a class vs Dispose() Just want some information regarding
Possible Duplicate: Best practices regarding equals: to overload or not to overload? Does anyone
Possible Duplicate: Naming Boolean columns in Rails What is the rails convention regarding names
Possible Duplicate: Consecutive Blank space Removal in C Prompt: A text file contains a
Possible Duplicate: void * arithmetic Hi guys I have a small question regarding pointer
Possible Duplicate: Why does InputStream#read() return an int and not a byte? Issue regarding
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Benefits of inline functions in C++? I have a confusion regarding the

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.