Initializing Class Member Variables, int type and point type - C++ Class

C++ examples for Class:Member Field

Description

Initializing Class Member Variables, int type and point type

Demo Code

#include <string>

using namespace std;

class Foo {/* www  . ja  va 2s.  c o  m*/
public:
   Foo() : counter_(0), str_(NULL) {}
   Foo(int c, string* p) : counter_(c), str_(p) {}
private:
   int counter_;
   string* str_;
};

int main() {

   string s = "bar";
   Foo(2, &s);
}

Related Tutorials