T
thomas
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--
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--