【发布时间】:2012-01-04 04:26:33
【问题描述】:
我有很多关于声明和实现的问题,根据大多数(书籍、教程、博客条目)的构造函数、方法和成员函数的类声明:
class Book
{
public:
Book(const string & author_,
const string & title_,
const string & publisher_,
double price_,
double weight_);
string getName()
{
string name;
name = author + ": " + title;
return name.substr(0, 40);
}
double getPrice();
double getWeight();
private:
string author, title, publisher;
double price, weight;
};
我了解所有的访问级别、构造函数、引用运算符(也是指针!)、指针运算符,但是当我读到一些不那么琐碎的东西时:
class Type
{
public:
enum TypeT {stringT, intT, doubleT, unknownT};
// 1. which means "explicit"?
// 2. what's ": typeId(typeId_)"? after the Ctor declaration
explicit Type(TypeT typeId_) : typeId(typeId_) {}
// 3. "const" after the declaration which means?
BaseValue * newValue() const
{
return prototypes[typeId]->clone();
}
TypeT getType() const
{
return typeId;
}
static void init();
{
prototypes[stringT] = new Value<string>("");
prototypes[intT] = new Value<int>(0);
prototypes[doubleT] = new Value<double>(0);
}
private:
TypeT typeId;
static vector<BaseValue *> prototypes;
};
我感到迷茫,真的没有找到关于上述几点的明确信息。
除了回答我的问题,如果你知道他们在哪里有这些语言“技巧”
【问题讨论】:
-
并不是真正的重复,因为他提出了三个具体问题,尽管我同意他应该参考另一个问题,以作为开始阅读 C++ 书籍的好地方。
标签: c++