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

The Archive Base Latest Questions

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

I am looking at someone’s code, I don’t understand how the object getting initialized

  • 0

I am looking at someone’s code, I don’t understand how the object getting initialized here:

template <typename String>
void test_numbers()
{
  SampleClass<String> compare;
  String lhs = "abc";
  String rhs = "efg";
  check_equality(compare(lhs, rhs), true);
}

The object compare is created of class type SampleClass and then assigned 2 strings when passed on as a parameter. How this initialization works? Any comments? suggestions?

  • 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-30T06:51:29+00:00Added an answer on May 30, 2026 at 6:51 am
    //I am initialised with my default constructor (no args) 
    SampleClass<String> compare;
    
    //I am initialised with my `const char*` constructor (and assignment operator)   
    String lhs = "abc";
    String rhs = "efg";
    
    //Compare (already initialised) is being invoked by it's `operator()`
    check_equality(compare(lhs, rhs), true);
    

    compare is already constructed. It has an operator() implemented that allows it to appear as a function, accepting arguments.

    you can make your own easily.

    struct op_test{
        int i;
        op_test(int i_) : i(i_){}
        int operator()(int j)const { return j*i; }
    };
    :::
    op_test ot(5);
    ot(6); //5*6
    

    The reason this is useful is because we can do thing like this.

    std::vector<int> a(700); //700 ints
    
    std::transform(a.begin(), a.end(), b.begin(), op_test(5));
    //or
    std::transform(a.begin(), a.end(), b.begin(), &my_func); //calls a function
    std::transform(a.begin(), a.end(), b.begin(), [](int i){ return i*5; }); //lambda
    

    see here:
    http://msdn.microsoft.com/en-us/library/5tk49fh2(v=vs.80).aspx
    useful with
    http://en.cppreference.com/w/cpp/algorithm

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

Sidebar

Related Questions

I'm looking at someone else's code, but it appears to RELEASE object VIDEO but
I was looking through someone's code one day and I was annoyed how they
Can someone recommend a simple c# code generator. I just looking something with methods
So, I'm looking through a java library (JScience) after someone here thoughfully pointed me
I was looking at someone else's code and wondering why anyone would do it
I am looking at someone else's vba excel code. they are doing ReDim Preserve
I was looking at someone else's code and noticed they called 'release' on an
I was looking at someone's code and saw that he repeatedly declared PrintStream out
I am looking over someone Else's code and noticed that some of the user
I'm looking through someone else's code and am not sure what this means. It

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.