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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:17:30+00:00 2026-05-28T06:17:30+00:00

I am relatively new to C++ (previous experience in Python and dabbled in Java)

  • 0

I am relatively new to C++ (previous experience in Python and dabbled in Java) and I am writing a small program as a familiarization project. As part of the program I am writing a class to decode some data and will eventually write a similar one that will perform the encoding. The code is something that I am sure I will reuse quite often and thought it would be interesting to create a library as part of the project.
My question is, what is considered the best practice for creating a library?

Edit: (Revised)

After asking this question, I realized that I didn’t know what I didn’t know. I have done some more research and this should help make my question more specific:

  • I am developing in Qt Creator. So specifics relating to Qt would be helpful, but not necessary.
  • I have created a new static library project in Qt (MyCodec) that, currently, has one class defined called MyDecoder.
  • As a library, my assumption is that, to add MyEncoder, I just create another class/header file.
  • What happens next is where I am uncertain. Do I just build the library? My understanding is that it will create (in Windows) a .lib and a .h file. Is there something I should do before this step? Are there options that will affect the way I interact with it?
  • Do I just include that header file in my program to access both classes that I wrote?
  • I found lots of answers on adding a .lib file to a project in Qt, so I don’t need that information.

Original Question: (for context)

My initial thought is that it would be the most convenient to create MyLib that includes both MyEncoder and MyDecoder classes.

  • If I were to do it that way, do I just declare both classes in the header?

  • I would like to create a DLL out of this library for portability and experience. I’m sure there is lots of information out there about creating and using DLLs (which is not the subject of this question), but if there is a particularly good tutorial (for Qt) please pass it along.

  • My assumption is that it would be best to use separate namespaces for MyEncoder and MyDecoder for this implementation vs. one namespace for MyLib?

I can see one trade off of this method being the size of the application, since including MyLib.h would include the code for the encoder and decoder (if the encoder and decoder were separate applications). This is assuming I am not using a DLL.

I guess what I am getting at is:

  • What methods are available (and recommended)?
  • What are the trade offs of each?
  • Where can I find documentation (tutorials/examples) on this specific subject? My search efforts have not yielded much for results.

If it helps to be more specific, I am doing my development using Qt 4.7.4 in Qt Creator.

  • 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-28T06:17:31+00:00Added an answer on May 28, 2026 at 6:17 am

    One “best practice” in C++ with regards to libraries is typically “you pay for what you use.”

    How this applies to your question is that you would have MyEncoder and MyDecoder in separate header files. So if the user wants to use a MyEncoder he would include MyEncoder.h, if he wanted to use MyDecoder he would include MyDecoder.h, and if he wanted to use both he would include both headers.

    The linker will typically only include the parts of the code that you use in the executable, so there is no penalty as far as code size goes, but there is a penalty in compile times, particularly if you start using advanced template techniques in your classes. Compile times can get pretty long in large projects, so it is important to be able to only include what you are going to use.

    Of course, sometimes it is also convenient to include everything with one header. So what you could have is this:

    • MyEncoder.h
    • MyDecoder.h
    • MyCodec.h

    and then MyCodec.h could include both MyEncoder.h and MyDecoder.h

    There is probably no good reason to have MyEncoder and MyDecoder in different namespaces, assuming they are meant to operate on the same type of data.

    You might want to have something like a MyCodec namespace, and declare MyEncoder and MyDecoder within that namespace.

    Updated for your revision:

    As a library, my assumption is that, to add MyEncoder, I just create
    another class/header file.

    That is a correct assumption.

    What happens next is where I am uncertain. Do I just build the
    library? My understanding is that it will create (in Windows) a .lib
    and a .h file. Is there something I should do before this step? Are
    there options that will affect the way I interact with it?

    I haven’t used Qt creator in a while, so I can’t speak with authority on it or how to access the relevant options. But as a general rule you will want to have at least 2 versions of your library; a debug version and a release version. If your library uses the Qt libraries, then when an application links to the debug version of your library, they will need to have the debug version of the Qt shared libraries in their path, and if they link to your release version they will need to have the release version of the Qt libs.

    There may also be options of whether you want to statically link to the C++ standard runtime libraries, or dynamically link to the DLLs.

    But essentially yes, you just build the library and then the application that uses it will link the library to the executable.

    Do I just include that header file in my program to access both
    classes that I wrote?

    You include the header file, and link to the .lib file. That’s all you should need to do.

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

Sidebar

Related Questions

Being relatively new to Python 2, I'm uncertain how best to organise my class
I'm a relatively new java programmer and I've been tinkering around with this program
I'm relatively new to J2ME and about to begin my first serious project. My
I'm relatively new to Python and am having problems programming with Scapy, the Python
Relatively new to python. I recently posted a question in regards to validating that
I am relatively new to C#, having done most of my previous programming in
Relatively new to Python, and I saw the following construct in the PyFacebook library
Relatively new to Python.. I would like to know how to check if a
Relatively new to rails and trying to model a very simple family tree with
Being relatively new to the .net game, I was wondering, has anyone had any

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.