Creating Temporary Instances with Functional Constructors - C++ Class

C++ examples for Class:Constructor

Introduction

string("Sam") creates a temporary instance.

Demo Code

#include <iostream>
#include <string>

using namespace std;

void WriteMe(string str)
{
    cout << "Here I am: " << str << endl;
}

int main()//from w  w w. ja  v a  2  s.  c  o  m
{
    WriteMe(string("Sam"));
    return 0;
}

Result


Related Tutorials