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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:16:00+00:00 2026-05-17T17:16:00+00:00

In msvc, I have functions like this and it builds but in gcc it

  • 0

In msvc, I have functions like this and it builds but in gcc it doesnt like it.

void classname::a(std::string &text)
{
    stdStringFromClass = text;
}

void classname::b(char *text)
{
    a(std::string(text));
}

The issue here is in the &, gcc I think is worried that since I just created that std::string, that passing by reference is risky, so it does not build, but msvc doesnt even warn me.

Why is this incorrect c++ to gcc I keep hearing that msvc is stricter than gcc.

Thanks

The error

AguiWidgetBase.cpp: In member function ‘void AguiWidgetBase::setText(char*)’:
AguiWidgetBase.cpp:91:27: error: no matching function for call to ‘AguiWidgetBase::setText(std::string)’
AguiWidgetBase.cpp:80:6: note: candidates are: void AguiWidgetBase::setText(std::string&)
AguiWidgetBase.cpp:88:6: note:                 void AguiWidgetBase::setText(char*)

would this be okay?

void classname::a(std::string &text)
{
    stdStringFromClass = text;
}

void classname::b(char *text)
{
   std::string k = text;
    a(k);
}
  • 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-17T17:16:01+00:00Added an answer on May 17, 2026 at 5:16 pm

    I have no idea why Visual studio allows you to compile this, but you can’t pass a reference to an anonymous object.

    Edit: Its ok for const reference, cause you can pass the temporary object as reference, just being able to modify it doesn’t make sense. That’s why we have rvalue references in C++0x.

    Edit2: To your edit, yes that would fix the problem, or just take a const reference as parameter in the a() method, you don’t seem to modify the parameter.

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

Sidebar

Related Questions

This code compiles fine with GCC and Clang but not with MSVC 2010: #include
I have a function signature similiar to this void Mutliply(const MatrixMN& a, const MatrixMN&
I have a simple C++ with Boost like this: #include <boost/algorithm/string.hpp> int main() {
Does the Sun compiler have a notation to mark functions as deprecated, like GCC's
In MSVC, a number of string functions offer the original, a safe version, and
My question is similar to this , but I have two strings (as char
I have a string command I'd like to execute asynchronously while writing to its
I'd like to be able to do this: std::unordered_map<icu::UnicodeString, icu::UnicodeString> mymap; However, when I
I have an MSVC project that uses freetype, and now I'm trying to move
[Cross-posted from lib-curl mailing list] I have a single threaded app (MSVC C++ 2005)

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.