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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:47:35+00:00 2026-06-18T20:47:35+00:00

When learning C++ in school we never really talked about how to build libraries,

  • 0

When learning C++ in school we never really talked about how to build libraries, so sorry for my rudimentary understanding.
From what I’ve read online, it seems like a library is just a collection of code that is already compiled, and then there is a .h file that lists what functions are accessible in that library.

For example when I #include <cmath> I can now call sin(x) without having access to the cmath code to compile it. My question is if this works with classes that have data in them.

So can I create a library

//AccumulatorLibrary.h
class Accumulator
{
public:
    int num;
    int increment() {num++};
    void otherFunctions(); //otherFunctions defined in the .lib file
}

And then call it

//Main
#include "AccumulatorLibrary.h"
#include <stdio>
int main()
{
    Accumulator A(0); //initalize num to 0
    Accumulator B(7); //initalize num to 7
    cout<<A.increment;
    cout<<B.increment;
    cout<<A.increment;
}

and get an output of 1 8 2 ?

In summary, if I figure out how to put a bunch of classes into a library file can I access any data I want to, as long as that data has an access function in the .h file?

Or a more basic question, do a .h and .lib file work exactly the same as regular c++ code except that it doesn’t have to be compiled when you use it, and you don’t have access to the code in the .lib file?

  • 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-18T20:47:37+00:00Added an answer on June 18, 2026 at 8:47 pm

    From what I’ve read online, it seems like a library is just a collection of code that is already compiled, and then there is a .h file that lists what functions are accessible in that library.

    Correct.

    My question is if this works with classes that have data in them.

    It does. A lot of C++ libraries expose classes and have their code precompiled in a library.

    Or a more basic question, do a .h and .lib file work exactly the same as regular c++ code except that it doesn’t have to be compiled when you use it…

    Wait, wait. .h files still contain C++ code (declarations and sometimes even inline implementations). .lib files are dynamically linked libraries. They’re the result of the compilation (and linkage) of the C++ source files.

    …and you don’t have access to the code in the .lib file?

    You do have access to it: open it using a disassembler. It just won’t be C++ anymore.

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

Sidebar

Related Questions

I have been learning C++ with some books from school that are from the
Sorry if this seems like a dumb question but I am just learning bash
I'm learning GRASP pattern at school and I have a question about the Creator
So I've been wondering, recently, in school, we've been learning about java threads.. Unlike
I was just learning about objects in school today and i know a function
I'm just learning to build a website. It's a school project and after I
I have no clue about trigonometry, despite learning it in school way back when,
So I'm learning about design patterns in school. Today I was told about the
I am learning C++ in school now. Currently using C++ with codeblocks on my
Learning about notifyAll made me question something about notify: in a typical situation we

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.