// 实现一个类 #include <iostream> using namespace std; class Book { public: Book( int p, char a, char n ); void print(); private: int page; char author; char name; }; Book::Book( int p, char a, char n ) { page = p; author = a; name = n; } void Book::print() { cout<<"书名是:"<<name<<endl; cout<<"作者是:"<<author<<endl; cout<<"页数为:"<<page<<endl; } int main() { Book book( 200, 'd', 't' ); book.print(); return 0; } <img src="http://img.blog.csdn.net/20150423112601853?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
原文地址:http://blog.csdn.net/zhaoyaqian552/article/details/45219321