I'm trying to debug a program for an assignment, and I believe most of the errors are fixed, but there are still one or two I am having trouble finding.
These are the compiler errors:
9.1.cpp(47): error C2275: 'Magazine' : illegal use of this type as an expression
1> 9.1.cpp(18) : see declaration of 'Magazine'
9.1.cpp(48): error C2144: syntax error : 'int' should be preceded by ')'
1>9.1.cpp(48): error C2780: 'void display(T)' : expects 1 arguments - 0 provided
1> 9.1.cpp(11) : see declaration of 'display'
1>9.1.cpp(48): error C2059: syntax error : ')'
Visual Studio 2010 underlines these as red:
display(Magazine);
display(int);
This is what the code looks like now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
// This program uses a template to display data of 2 different types.
// An object of type Magazine and an integer
#include "stdafx.h"
#include<iostream>
#include<string.h>
#include<conio.h>
using namespace std;
template<class T>
void display(T x)
{
cout<<endl<<"My output value is "<<endl;
cout<<" "<<T.x;
}
class Magazine
{
private:
int chartNum;
char cover[30];
double cost;
public:
Magazine(int sn,char t[], double pr);
friend ostream& operator<<(ostream& out, Magazine b);
};
Magazine::Magazine(int sn, char t[], double pr)
{
Magazine::chartNum = sn;
strcpy(Magazine::cover, t);
Magazine::cost = pr;
}
ostream& operator<<(ostream& out, Magazine b)
{
out<<"Magazine number "<<b.chartNum<<" coverd "<<b.cover<<endl;
out<<" sells for "<<b.cost<<endl;
return(out);
}
void main()
{
Magazine aMagazine(222,"New York Journal",12.99);
int aNumber = 91;
display(Magazine);
display(int);
getch();
}
|
Please let me know if I need to provide anything else. Thank you for any assistance!