Ok this is funny Chris, I pasted your code into a new file and compiled it, it worked however I got the following warnings.
<br />
--------------------Configuration: test - Win32 Debug--------------------<br />
Compiling...<br />
test.cpp<br />
c:\documents and settings\np0383\my documents\c++\test.cpp(18) : warning C4508: 'main' : function should return a value; 'void' return type assumed<br />
c:\program files\microsoft visual studio\vc98\include\deque(208) : warning C4786: 'std::reverse_iterator<std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std<br />
::allocator<char> > > >::const_iterator,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<ch<br />
ar> > const *,int>' : identifier was truncated to '255' characters in the debug information<br />
c:\program files\microsoft visual studio\vc98\include\deque(207) : while compiling class-template member function '__thiscall std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<ch<br />
ar,std::char_traits<char>,std::allocator<char> > > >::~std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'<br />
c:\program files\microsoft visual studio\vc98\include\deque(208) : warning C4786: 'std::reverse_iterator<std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std<br />
::allocator<char> > > >::iterator,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int><br />
' : identifier was truncated to '255' characters in the debug information<br />
c:\program files\microsoft visual studio\vc98\include\deque(207) : while compiling class-template member function '__thiscall std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<ch<br />
ar,std::char_traits<char>,std::allocator<char> > > >::~std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >(void)'<br />
warning C4786: 'std::stack<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocat<br />
or<char> > > > >::~stack<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<br />
<char> > > > >' : identifier was truncated to '255' characters in the debug information<br />
c:\program files\microsoft visual studio\vc98\include\stack(22) : warning C4786: 'std::stack<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::al<br />
locator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >::stack<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::alloc<br />
ator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >' : identifier was truncated to '255' characters in the debug information<br />
c:\program files\microsoft visual studio\vc98\include\stack(27) : warning C4786: 'std::stack<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::al<br />
locator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >::empty' : identifier was truncated to '255' characters in the debug information<br />
c:\program files\microsoft visual studio\vc98\include\deque(208) : warning C4786: 'std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > <br />
>::~deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information<br />
c:\program files\microsoft visual studio\vc98\include\deque(191) : warning C4786: 'std::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > <br />
>::deque<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information<br />
Linking...<br />
<br />
test.exe - 0 error(s), 8 warning(s)<br />
I find it odd to say the least that it is throwing that many warnings, yet it works. Hmm... Anyway, let me just show you exactly what my previous code looked like:
#include <iostream>
#include <vector>
#include <stack>
#include <tchar.h>
using namespace std;
template <class T>
class Math{
public:
Math(){};
T Add(T a, T b)
{
return a + b;
}
T Subtract(T a, T b)
{
return a - b;
}
T Multiply(T a, T b)
{
return a * b;
}
T Divide(T a, T b)
{
return a / b;
}
};
void main()
{
Math<double> dMath;
double dReturn = dMath.Add(12.34,36.654);
cout << "12.34 plus 36.654 = " << dReturn << endl << endl;
printf(_T("vector fun begins...\n\n"));
vector<int> vList;
for(int i = 1;i <= 20;i++)
{
vList.push_back(i);
cout << "Number " << i << " added to vector." << endl;
}
for(i = 20;i > 0;i--)
{
vList.pop_back();
cout << "Number " << i << " being removed from vector." << endl;
}
vList.~vector();
cout << "Fun with stacks begins" << endl << endl;
stack<string> strStack;
strStack.push("Nick");
strStack.push("Megan");
while(!strStack.empty())
{
cout << strStack.top() << endl;
strStack.pop();
}
cout << "Fun with stacks is over." << endl;
}
It's still not working within this code, not sure why though.
Nick Parker
|