I'm just learning how to use templates so I don't really have any experience with them, and I can't seem to understand what I'm supposed to do ... there's apparently an issue with the showWeaponSpecs:
error C2783: 'WS AssaultRifle::showWeaponSpecs(void)' : could not deduce template argument for 'WS' : see declaration of 'AssaultRifle::showWeaponSpecs'
AssaultRifle2.h
#include <iostream>
#include <string>
using namespace std;
class AssaultRifle
{
private:
string Name;
string FurnitureType;
string Caliber;
int MagazineSize;
int MaxCarryingCapacity;
public:
template <typename N>
N setName(N n)
{ Name = n; }
template <typename FT>
FT setFurnitureType (FT ft)
{ FurnitureType = ft; }
template <typename C>
C setCaliber (C c)
{ Caliber = c; }
template <typename MS>
MS setMagazineSize (MS ms)
{ MagazineSize = ms; }
template <typename MCC>
MCC setMaxCarryingCapacity (MCC mcc)
{ MaxCarryingCapacity = mcc; }
template <typename WS>
WS showWeaponSpecs()
{
cout << "Assault Rifle: " << Name << endl;
cout << "Furniture Type: " << FurnitureType << endl;
cout << "Caliber: " << Caliber << endl;
cout << "Magazine Size: " << MagazineSize << endl;
cout << "Max Carrying Capacity: " << MaxCarryingCapacity << endl << endl;
}
};
WeaponCreator2.cpp
#include <iostream>
#include "AssaultRifle2.h"
using namespace std;
int main()
{
AssaultRifle M16A4;
M16A4.setName("M16A4");
M16A4.setFurnitureType("Black Polymer");
M16A4.setCaliber("5.56 x 45mm NATO");
M16A4.setMagazineSize(30);
M16A4.setMaxCarryingCapacity(300);
M16A4.showWeaponSpecs();
return 0;
}