By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,657 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,657 IT Pros & Developers. It's quick & easy.

No identifier required?

P: n/a
Hi,

i was just testing a class within main and was wondering why this works :
#include <iostream>

class testclass {
public:
testclass (int _test) : test(_test){};
private:
int test;
};
int main () {
testclass (8);
std::cout<<"Seems to work?"<<std::endl;
return 0;
}
My Question: What does "testclass (8);" do? (works without compilation
error with g++ (gcc) (3.3.3), stdout:"Seems to work?" ).

regards marbac

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
marbac wrote:
...
int main () {
testclass (8);
std::cout<<"Seems to work?"<<std::endl;
return 0;
}
My Question: What does "testclass (8);" do? (works without compilation
error with g++ (gcc) (3.3.3), stdout:"Seems to work?" ).
...


'testclass (8)' is an expression statement that creates a temporary
object of type 'testclass'. The object is then immediately destroyed.
That's all.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #2

P: n/a

"marbac" <ma****@chello.at> wrote in message
news:VZ*******************@news.chello.at...
Hi,

i was just testing a class within main and was wondering why this works :
#include <iostream>

class testclass {
public:
testclass (int _test) : test(_test){};
private:
int test;
};
int main () {
testclass (8);
std::cout<<"Seems to work?"<<std::endl;
return 0;
}
My Question: What does "testclass (8);" do?
Creates a type 'testclass' object, then immediately
destroys it.
error with g++ (gcc) (3.3.3), stdout:"Seems to work?" ).


It works. It's well-defined.

-Mike
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.