//cstack.h
# ifndef _STACK_H__
#define _STACK_H__
#include<iostream>
#include<vector>
template< class Type ,int Size = 3>
class cStack
{
Type *m_array;
int m_Top;
int m_Size;
public:
cStack();
cStack(const Type&);
cStack(const cStack<Type,Size> &);
int GetTop()const;
bool Is_Full()const;
bool Is_Empty()const;
void InsertValue(const Type&);
void RemeoveValue();
void show();
~cStack();
friend std::ostream& operator <<(std::ostream &, const cStack<Type,Size> &);
};
// iam writing only one function defination because linking is because of this function
template< class Type,int Size >
std::ostream& operator << (std::ostream &os, const cStack<Type,Size> &s)
{
for(int i=0; i<=s.GetTop();i++)
{
os << s.m_array[i];
}
return os;
}
//main.cpp
#include "cStack.h"
#include <string>
#include<iostream>
int main()
{
cStack<int> sobj(1);
std::cout << sobj;
}
我編譯時出現以下錯誤:
error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class cStack<int,3> const &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected][email protected]@@Z) referenced in function _main
你能從'主提供的代碼()'(或者'_main()'),其中函數被調用? – 2010-04-27 13:12:49
main() { cStack sobj(1); } –
Suri
2010-04-27 13:15:50
對不起,這裏是我的主 主 { cStack sobj(1); std :: cout << sobj; –
Suri
2010-04-27 13:19:50