473,385 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

temporary object in function call

Visual Studio C++ compiles the following:

class someclass {
//
};

void somefunction(someclass &) {
//
}

int main() {
somefunction(someclass());
return 0;
}

But Dev-C++ (Bloodshed) and g++ don't. I wonder if Visual Studio C++
is smarter here.
Jun 27 '08 #1
2 1334
th*****@hotmail.com wrote:
Visual Studio C++ compiles the following:

class someclass {
//
};

void somefunction(someclass &) {
//
}

int main() {
somefunction(someclass());
return 0;
}

But Dev-C++ (Bloodshed) and g++ don't. I wonder if Visual Studio C++
is smarter here.
No, Bloodshed (which uses g++) and g++ are correct. You can't bind a
temporary to a non-const ref. If you turn of MS extensions (I think
it's /Za) VStudio will also properly generate an error.
Jun 27 '08 #2
red floyd wrote:
th*****@hotmail.com wrote:
>Visual Studio C++ compiles the following:

class someclass {
//
};

void somefunction(someclass &) {
//
}

int main() {
somefunction(someclass());
return 0;
}

But Dev-C++ (Bloodshed) and g++ don't. I wonder if Visual Studio C++
is smarter here.

No, Bloodshed (which uses g++) and g++ are correct. You can't bind a
temporary to a non-const ref. If you turn of MS extensions (I think
it's /Za) VStudio will also properly generate an error.
Also setting warning levels to 4 in VStudio will produce a warning.

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Kai-Uwe Bux | last post by:
Hi folks, I have trouble writing a class, derving from stringstream, that collects item and once it's done will write them to std::cout in one go. It works fine except when I use it as a...
5
by: White Wolf | last post by:
Hi, I would like to double check how long a temporary returned by a function lives? Suppose I have an instance of a class type C, which has a member function returning some sort of...
8
by: pt | last post by:
Hallo, i wonder how it is going to be of this code below regarding of the return of temporary object. Prototypes: =========== bool Activation(TCHAR *c); std::basic_string<TCHAR> GetFile();
7
by: Chad Zalkin | last post by:
We are evaluating some old code that was written as part of our math library. This code uses some optimizations that I'm not sure are necessary or safe, but is a source of debate between my...
11
by: Marco Wedekind | last post by:
Hello all, I have a strange compiler behaviour with this code: ---- Begin of code snippet ---- class Base { public: static unsigned int ClassId();
2
by: xllx.relient.xllx | last post by:
Assuming compiler optimizations are set to off, specifically to not allow the compiler to elide the copy constructor, would the following hold true?: If you call a function with an user-defined...
17
by: Klaas Vantournhout | last post by:
Hi all, I was wondering if it is possible if you can check in a function if one of the arguments is temporary. What I mean is the following. A is a class, foo is a function returning a class...
1
by: subramanian100in | last post by:
Consider the following: int x; int y; int z; (x+y) = z; For this statement, I get the following error with g++ compiler: error: non-lvalue in assignment Suppose I have a class Test and x,...
5
by: Juha Nieminen | last post by:
Let's assume we have a class like this: //--------------------------------------------------------- #include <iostream> class MyClass { public: MyClass() { std::cout << "constructor\n"; }...
5
by: coolguyaroundyou | last post by:
Consider the following codes: class abc { int i; public: abc() : i(0) {} void func() { .....some code....} };
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.