c++错题库
2015-06-20 22:49
375 查看
1.当类中有typedef int value_type 这一类的用法时,在类外调用该类型 T::value_type 必须在此语句前面加上typename 否则编译器不知道value_type是类型还是成员。
typename 用法!!!
http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords/613132#613132 http://blog.csdn.net/meijia_tts/article/details/7394220
2.类中有static成员 出现unreference 错误
类中声明的static成员 必须在类外再声明一次,此时不用加static
3.delete 失效:
4.E:\QtProject\Download\ConfigParser.cpp:68: error: variable 'std::ifstream stream' has initializer but incomplete type
std::ifstream stream(path.c_str());
^
出现这种情况 是因为没有包含fstream头文件。 注意 ifstream 在fstream头文件里包含 不是ifstream头文件
typename 用法!!!
http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords/613132#613132 http://blog.csdn.net/meijia_tts/article/details/7394220
2.类中有static成员 出现unreference 错误
类中声明的static成员 必须在类外再声明一次,此时不用加static
3.delete 失效:
class ConfigParserImpl : public ConfigParser { public: ConfigParserImpl(); virtual string getUrl(); virtual void setUrl(); virtual string getSavePath(); virtual void setSavePath(); private: };
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#808000;">class</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Test</span>
{
public:
Test()
{
value = 100;
}
int value;
};
int main(int argc, char *argv[]) { Test* t = Singleton<Test>::getInstance(); cout<<t->value<<endl; Test* t2 = t; delete t2; cout<<t2->value<<endl; return 0; }为什么delete t2 不会造成影响
4.E:\QtProject\Download\ConfigParser.cpp:68: error: variable 'std::ifstream stream' has initializer but incomplete type
std::ifstream stream(path.c_str());
^
出现这种情况 是因为没有包含fstream头文件。 注意 ifstream 在fstream头文件里包含 不是ifstream头文件
相关文章推荐
- 认识C++中的bitset类型
- C语言20150620
- c++学习笔记:变量
- C语言中fgetc()函数的返回值意义
- C++中的new/delete和malloc/free的区别
- C++基本知识点总结
- C语言回顾(四、字符串及其处理函数重写)——iOS开发基础
- C/C++各种类型int、long、double、char表示范围(最大和最小)
- c语言第二周总结-结构体
- 《C++专项练习》 — (2)
- 《C++专项练习》 — (2)
- c语言第二周总结-函数
- C++文件读写详解(ofstream,ifstream,fstream)
- C++学习笔记(三)STL简介(二)
- 【leetcode c++】26 Remove Duplicates from Sorted Array
- Effective C++条款16解读:成对使用new和delete时要采取相同形式
- C语言一个双向链表的实现
- C语言单链表的实现
- Effective C++条款20解读:宁以pass by reference to const替换pass by value
- c语言第二周总结-数组2