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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:43:46+00:00 2026-06-18T04:43:46+00:00

When I begin to learn C++ and algorithms. I want to group code in

  • 0

When I begin to learn C++ and algorithms. I want to group code in module paradigm. so I had divide the sort procedure into 3 files, as follows:

sort.h

namespace sort
{
    void insertSort(int* a,int size);    
}

sort.cpp

#include "sort.h"
namespace sort
{
}
void sort::insertSort(int* a,int size)
{
    int i,j,key;
    for(j=1;j<size;j++)
    {
        key=a[j];
        i=j-1;
        while(i>=0 && a[i]>key)
        {
            a[i+1]=a[i];
            i=i-1;
        }
        a[i+1]=key;
    }
}

main.cpp

#include<iostream>
#include"sort.h"
int main()
{
    int a[6]={5,2,4,6,1,3};
    sort::insertSort(a,6);
    for(int i=0;i<6;i++) std::cout<<a[i]<<'\t';
    return 0;
}

When I use Dev-C++ to compile the three files. I got the the below error information:

[Linker Error] undefined reference to `sort::insertSort(int*, int)’

I don’t know why. I think I have include the file “sort.h”, so why is it also telling me that the compile can’t reference to the method sort::insertSort()?

  • 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-18T04:43:48+00:00Added an answer on June 18, 2026 at 4:43 am

    When you’re building the entire program, make sure you’re linking all the object files together. The linker is complaining because your main() function is calling the sort::insertSort function, which has been declared in sort.h, but the definition for which has not been included in the program as a whole.

    I don’t know offhand what parameters to your particular Dev-C++ environment are required, but typically, make sure that all the cpp files are in the command line you send to the compiler frontend.

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

Sidebar

Related Questions

I begin to learn re module. First I'll show the original code: import re
I am new in iPhone Developer so I want learn SQLite Database from begin
I'm begin to learn php by my self, for example I have this code,suppose
i have complete sql and plsql course and , i want to begin learn
I am trying to learn PHP classes so I can begin coding more OOP
I'm trying to learn how to use MySQL stored procedures. MySQL accepted my procedure:
I've just begun to learn how to write stored procedures and SQL code outside
I'm trying to learn c++ and was trying using sort and qsort. sort() works
I just begin to learn jquery ajax framework here is my first attempt: <div>
I've been trying to learn how to write C-extensions for Python and want to

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.