怎么写c++头文件,我这样写为什么不行?

来源:百度知道 编辑:UC知道 时间:2024/06/30 14:41:46
c++头文件中(文件名是song.h):
# include "iomanip.h"
class Song
{
public:
void aaa();
void bbb();
void ccc();
};

c++的cpp文件中(文件名是song.cpp):
# include "Song.h"
void Song::aaa()
{
cout<<"aaa"<<endl;
}

void Song::bbb()
{
cout<<"bbb"<<endl;

}

void Song::ccc()
{
cout<<"ccc"<<endl;

}
怎么写c++头文件,我这样写为什么不行?
出现这种错误:
Compiling...
f.cpp
Linking...
f.obj : error LNK2001: unresolved external symbol "public: void __thiscall Song::ccc(void)" (?ccc@Song@@QAEXXZ)
f.obj : error LNK2001: unresolved external symbol "public: void __thiscall Song::bbb(void)" (?bbb@Song@@QAEXXZ)
f.obj : error LNK2001: unresolved external symbol "public: void __thiscall Song::aaa(void)" (?aaa@Song@@QAEXXZ)
Debug/bbbb.exe : fatal error LNK

你的 song.cpp 包含到你的工程里面了吗?

另: song.h 最好加上

#ifndef _SONG_H_
#define _SONG_H_

代码代码代码代码代码

#endif

我觉得代码都对,link错,就重新生成解决方案试试吧

# include "iomanip"
这样写
新的C++标准