Difference between revisions of "Effective Analysis Programming Part 1"

From Gridkaschool
Line 14: Line 14:
 
* http://www.parashift.com/c++-faq/
 
* http://www.parashift.com/c++-faq/
 
* http://herbsutter.com/gotw/
 
* http://herbsutter.com/gotw/
  +
  +
==Standard Template Library==
  +
''map''
  +
#include <map>
  +
#include <iostream>
  +
  +
using std::map;
  +
using std::cout;
  +
using std::endl;
  +
  +
struct A {
  +
A(): _p(0) {
  +
cout<<"A::A()"<<endl;
  +
}
  +
A(int p): _p(p) {
  +
cout<<"A::A(int p)"<<endl;
  +
}
  +
A& operator=(A const& other) {
  +
_p=other._p;
  +
cout<<"A& A::operator=A const& other)"<<endl;
  +
return *this;
  +
}
  +
int _p;
  +
};
  +
  +
int main() {
  +
map<int,A> m;
  +
m[1]=A(42);
  +
m.insert(std::make_pair(4,A(11)));
  +
for(std::pair<int,A> p: m) {
  +
cout<<"m["<<p.first<<"]: "<<p.second._p<<'\n';
  +
}
  +
return 0;
  +
}

Revision as of 12:41, 15 August 2013

Literature on C++

books

  • The C++ Programming Language, Bjarne Stroustrup
  • Effective C++, Scott Meyers
  • More Effective C++: 35 New Ways to Improve Your Programs and Designs
  • Modern C++ Design, Andrei Alexandrescu
  • The C++ Standard Library, Nicolai M. Josuttis
  • C++ Templates, David Vanevoorde, Nicolai M. Josuttis
  • Exceptional C++, Herb Sutter
  • More Exceptional C++, Herb Sutter

links

Standard Template Library

map

#include <map>
#include <iostream>

using std::map;
using std::cout;
using std::endl;

struct A {
  A(): _p(0) {
    cout<<"A::A()"<<endl;
  }
  A(int p): _p(p) {
    cout<<"A::A(int p)"<<endl;
  }
  A& operator=(A const& other) {
    _p=other._p;
    cout<<"A& A::operator=A const& other)"<<endl;
    return *this;
  }
  int _p;
};

int main() {
  map<int,A> m;
  m[1]=A(42);
  m.insert(std::make_pair(4,A(11)));
  for(std::pair<int,A> p: m) {
    cout<<"m["<<p.first<<"]: "<<p.second._p<<'\n';
  }
  return 0;
}