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

  • Home
  • SEARCH
  • 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 1028713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:26:01+00:00 2026-05-16T12:26:01+00:00

I have a class which has a constructor that takes a const char* .

  • 0

I have a class which has a constructor that takes a const char*. It is:

c::c(const char* str) {
    a = 32;
    f = 0;
    data = new char[strlen(str)];
    memcpy(data, str, strlen(str));
}

And a function which takes one of them:

int foo(c& cinst);

You can call this function either by passing it an instance of a c:

c cinst("asdf");
foo(cinst);

or, because we have explicit initialization, you can do:

foo("asdf");

which will make a c by passing the constructor “asdf” and then pass the resulting object to foo.

However, this seems like it might be quite a bit less efficient than just overloading foo to take a const char*. Is it worth doing the overload for the speed or is the performance impact so small that it’s a waste of space to make an overload? I’m trying to make my program as fast as possible, so speed is an important factor, so is size, but not so much.

  • 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-16T12:26:02+00:00Added an answer on May 16, 2026 at 12:26 pm

    What will foo be doing with that const char*? If it’s just going to make it own c object, then there’s no point.

    If it is going to use the char* directly (and the existing foo just pulled the char* out of the c object), then it would be better to write an overload.

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

Sidebar

Related Questions

I have a service class which has overloaded constructors. One constructor has 5 parameters
I have a class which has a function to retrieve children elements from a
I have an Assembly(A) which defines a Managed class which has a public constructor
I have a case class that has a few parameters for its constructor, and
I have a class, MyThread which implements Callable <String>. The class has a constructor
I have a class which takes two arguments on it's constructor, an int and
I have a kind of buffer class that takes an std::vector as a constructor
I have a base class, B, which has two constructors, one with no paremeters
I have a class which has a private attribute which is a reference to
I have a class which has a private attribute vector rectVec; class A {

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.