您的位置:首页 > 编程语言 > C语言/C++

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 失效:

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头文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: