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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:17:38+00:00 2026-05-23T16:17:38+00:00

really trying to solve the errors, double checked everything. please help. New to c++,

  • 0

really trying to solve the errors, double checked everything. please help.
New to c++, please be kind.

header file (.h)

#ifndef GUARD_Optimized_quick_sort_h
#define GUARD_Optimized_quick_sort_h

#include <vector>
#include <list>
#include <iterator>

using namespace std;

template <class T> class optimized_quick_sort 
{
    public:
        optimized_quick_sort(vector<T> array) 
        {
            this->array = array;
        }

        optimized_quick_sort(list<T> array)
        {
            vector<T> temp(array.begin(), array.end());
            this->array = temp;
        }

        vector<T> sort()
        {
            typename vector<T>::iterator begin = array.begin();
            typename vector<T>::iterator end = array.end();

            quick_sort(begin, end);
            return array;
        }

    private:

        vector<T> array;


        int quick_sort( vector<T>::iterator , vector<T>::iterator);
        int insertion_sort(vector<T>::iterator, vector<T>::iterator);
        vector<T>::size_type devide(vector<T>::iterator, vector<T>::iterator );
};

#endif

.cpp file

#include "optimized_quick_sort.h"

#include <iostream>
 using namespace std;

template <class T>
optimized_quick_sort<T>::quick_sort( vector<T>::iterator begin, vector<T>::iterator end)
{

    if(iterator::distance(begin, end) <= 5)
    {
        this->insertion_sort(begin, end);
    }
    else 
    {

        typename vector<T>::size_type devider;

        devider = devide(begin, end);

        quick_sort(begin + (devider+1),end);
        quick_sort(begin,begin + (devider-1));
    }

    return 1;
}

template <class T>
optimized_quick_sort<T>::devide(vector<T>::iterator begin, vector<T>::iterator end)
{
    return distance(begin, end)/2;
}

template <class T>
optimized_quick_sort<T>::insertion_sort(vector<T>::iterator begin, vector<T>::iterator end)
{
    return 1;

}

int main(int argc, char* argv[])
{ 
    vector<int> vec;
    int temp;
    while(cin >> temp)
        vec.push_back(temp);

    list<int> l(vec.begin(),vec.end());

    optimized_quick_sort<int> obj = optimized_quick_sort<int>(l);

    vec = obj.sort();

    vector<int>::iterator iter = vec.begin() ;

    while(iter != vec.end())
        cout << *iter++;

    cout << endl;
    return 1;
}

errors:

optimized_quick_sort.cpp:7: error: expected constructor, destructor, or type conversion before ‘(’ token

optimized_quick_sort.cpp:29: error: expected constructor, destructor, or type conversion before ‘(’ token

optimized_quick_sort.cpp:35: error: expected constructor, destructor, or type conversion before ‘(’ token

optimized_quick_sort.h: In member function ‘std::vector<T, std::allocator<_CharT> > 
optimized_quick_sort<T>::sort() [with T = int]’:

optimized_quick_sort.cpp:52:   instantiated from here

optimized_quick_sort.h:29: error: no matching function for call to ‘optimized_quick_sort<int>::quick_sort(__gnu_cxx::__normal_iterator<int*, std::vector<int, 
std::allocator<int> > >&, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >&)’

optimized_quick_sort.h:38: note: candidates are: int optimized_quick_sort<T>::quick_sort(int&, int&) [with T = int]
  • 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-23T16:17:39+00:00Added an answer on May 23, 2026 at 4:17 pm

    You’re missing the return type in all of your function implementations, as well as a little typename for the iterators, example:

    template <class T>
    int optimized_quick_sort<T>::quick_sort( typename vector<T>::iterator begin, typename vector<T>::iterator end)
    ^^^                                      ^^^^^^^^                            ^^^^^^^^
    {
      // ...
    }
    

    Also, as a design tip, directly initialize your stuff in the ctor-initializer:

    optimized_quick_sort(vector<T> array)
      : array(array)
    { //^^^^^
    }
    
    optimized_quick_sort(list<T> array)
      : array(array.begin(), array.end())
    { //^^^^^
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In trying to solve the ajax back button problem I have found the Really
Really stuck on trying to write code to unzip a file or directory on
I'm trying to solve a really simple problem of finding object position under force
Hello everyone, I have been banging my head really hard trying to solve this
I am really trying to show what htmlentities gives me, but it doesn't give
What i am really trying to achieve is to full control the active TabItem
i am really trying to do this but i am failing to find a
I'm really trying to understand the difference between OpenID and OAuth? Maybe they're two
I'm really trying to switch to emacs, but learning to setup the environment is
Really, really trying to find a plugin that gives adds functionality to the image-resize

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.