Skip to content

Commit c053d1c

Browse files
committed
feat : C++ 11 added
1 parent 5432b69 commit c053d1c

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

20.C++ 11/1_lambda_expression.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# include<iostream>
2+
using namespace std;
3+
4+
int main(){
5+
6+
[](int x,int y){
7+
cout<<"sum is "<<x+y<<endl;
8+
}
9+
(10,30);
10+
}

20.C++ 11/2_shared_pointer.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# include<iostream>
2+
# include<memory>
3+
using namespace std;
4+
5+
class rectangle
6+
{
7+
int length;
8+
int breadth;
9+
public:
10+
rectangle(int l,int b){
11+
length=l;
12+
breadth=b;
13+
}
14+
int area(){
15+
return length*breadth;
16+
}
17+
};
18+
19+
int main()
20+
{
21+
shared_ptr<rectangle> ptr(new rectangle(10,5));
22+
cout<<ptr->area()<<endl;
23+
shared_ptr<rectangle> ptr2;
24+
ptr2=ptr;
25+
cout<<"ptr2 "<<ptr2->area()<<endl;
26+
cout<<"ptr "<<ptr->area()<<endl;
27+
cout<<ptr.use_count()<<endl;
28+
}

20.C++ 11/3_unique_pointer.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# include<iostream>
2+
# include<memory>
3+
using namespace std;
4+
5+
6+
class rectangle{
7+
int length;
8+
int breadth;
9+
public:
10+
rectangle(int l,int b){
11+
length=l;
12+
breadth=b;
13+
}
14+
int area(){
15+
return length*breadth;
16+
}
17+
};
18+
19+
int main(){
20+
unique_ptr<rectangle> ptr(new rectangle(10,5));
21+
cout<<ptr->area()<<endl;
22+
unique_ptr<rectangle> ptr2;
23+
ptr2=move(ptr);
24+
cout<<ptr2->area();
25+
cout<<ptr->area();
26+
}

20.C++ 11/4_inclass_initializer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# include<iostream>
2+
# include<memory>
3+
using namespace std;
4+
5+
class test{
6+
int x=10;
7+
int y=13;
8+
public:
9+
test(int a,int b){
10+
x=a;
11+
y=b;
12+
}
13+
test():test(1,1)
14+
{}
15+
};
16+
int main()
17+
{}

20.C++ 11/5_demo_ellipses.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# include<iostream>
2+
# include<cstdarg>
3+
using namespace std;
4+
5+
int sum(int n,...)
6+
{
7+
va_list list;
8+
va_start(list,n);
9+
int x;
10+
int s=0;
11+
for(int i=0;i<n;i++){
12+
x=va_arg(list,int);
13+
s+=x;
14+
}
15+
return s;
16+
}
17+
int main(){
18+
cout<<sum(3,10,20,30)<<endl;
19+
cout<<sum(5,1,2,3,4,5)<<endl;
20+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy