Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > constructor wit...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 43357 of 48044
Post > Topic >>

constructor with/without semicolon

by thomas <FreshThomas@[EMAIL PROTECTED] > Feb 16, 2008 at 06:59 PM

for the following code, line L can also be written as
A(int i):data(i){};             //   L1
A(int i):data(i){}              //   L2

As I know, L2 works because it's a function;
but how can L1 work? It seems to be a declaration.

---code---
#include<iostream>
using namespace std;

class A{
	int data;
public:
	A(int i):data(i){}                   //  L
	void B(){
		cout<<data<<endl;
	}
};

int main(){
	A(3).B();
}

---code--
 




 4 Posts in Topic:
constructor with/without semicolon
thomas <FreshThomas@[E  2008-02-16 18:59:31 
Re: constructor with/without semicolon
Ian Collins <ian-news@  2008-02-17 16:09:28 
Re: constructor with/without semicolon
=?ISO-8859-1?Q?Marcel_M=F  2008-02-17 08:57:50 
Re: constructor with/without semicolon
James Kanze <james.kan  2008-02-17 04:44:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:38:32 CDT 2008.