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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:39:07+00:00 2026-06-17T20:39:07+00:00

I have made the following C++ program which is made up of 3 files:

  • 0

I have made the following C++ program which is made up of 3 files:

The thing.h file

    #ifndef THING_H
#define THING_H

class thing{
  double something;
  public:
         thing(double);
         ~thing();
         double getthing();
         void setthing(double);  
         void print();  
};

#endif

The thing.cpp file

  #include <iostream>
#include "thing.h"

thing::thing(double d){
something=d;                    
}

thing::~thing(){
std::cout << "Destructed" << std::endl;                
}

double thing::getthing(){
return something;       
}

void thing::setthing(double d){
something = d;     
}

void thing::print(){
std::cout <<"The someting is " << something << std::endl;     
}

The main file

    #include <iostream>
#include "thing.h"

int main(){

thing t1(5.5);
t1.print();
t1.setthing(7.);
double d=t1.getthing();
std::cout << d << std::endl;

system("pause");
return 0;    
}

I had made this program previously all in one file and it ran perfectly but when I try split it into seperate files to create a header I get a linker error, here is the errors I get when I try run it from the main file:

  [Linker error] undefined reference to `thing::thing(double)' 
  [Linker error] undefined reference to `thing::print()' 
  [Linker error] undefined reference to `thing::setthing(double)' 
  [Linker error] undefined reference to `thing::getthing()' 
  [Linker error] undefined reference to `thing::~thing()' 
  [Linker error] undefined reference to `thing::~thing()'
  ld returned 1 exit status  

From the above errors it seems asthough the main file doesnt recognise the functions inside the header, how do I fix this please?

  • 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-17T20:39:08+00:00Added an answer on June 17, 2026 at 8:39 pm

    In slightly less pedantic terms:

    Your header file thing.h declares “what class thing should look like”, but not its implementation, which is in the source file thing.cpp. By including the header in your main file (we’ll call it main.cpp), the compiler is informed of the description of class thing when compiling the file, but not how class thing actually works. When the linker tries to create the entire program, it then complains that the implementation (thing::print() and friends) cannot be found.

    The solution is to link all the files together when creating the actual program binary. When using the g++ frontend, you can do this by specifying all the source files together on the command line. For example:

    g++ -o main thing.cpp main.cpp
    

    will create the main program called “main”.

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

Sidebar

Related Questions

So I have a program that runs something like the following public class SHandler
I have a library, libfoo which is made of the following files: base.hpp #ifndef
I have a simple nav made up of the following HTML; <div class=inner> <div
I have made a small function which should print some InfoPath files. It is
I have the following files in my code base: StandardUnits.Numbers.Double using System; using System.Collections.Generic;
I have made the following method which runs hard-coded xPath queries in a hard-coded
I have the following ValidationRule class in WPF public class EmptyFieldValidationRule: BaseValidationRule { public
I have a problem in the socket of the following code which made the
I have created a sitecollection and in AAM I have made following settings for
I have made the following regexp for extracting robots links: re.compile(r/\S+(?:\/+)) And i get

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.