|
Error C2146: syntax error : missing ',' before identifier 'C4'
I'm having major problems with my main for this program, I have looked at it and tried to de-bug it for hours, yet there still hasn't been much success. I was wondering if someone with their C++ expertise could help me out!
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include <iostream>
using namespace std;
template <class T>
class Set {
private:
T *s; //array of T pointers
int size;
public:
Set() {
s = new T[1000]
for (int x = 0; x < 1000; x++)
s+x = 0;
size = 1;
}
Set (T *a, int b) {
*s = &a;
size = b;
}
Set (Set& t) { //copy constructor
size = t.size;
for (int x = 0; x < size; x++) {
s+x = t+x;
}
} //since copy constructor is created we need to overload the operator=
~Set() {
cout << "Set destructor is called" << endl;
}
void add (T a) {
for (int l = 0; l < size; l++) {
if (a == s+l) {
throw new Set_Exception("The element already exists in the set");
}
else if (size + 1 > 1000) {
expand();
x+l = &a;
*s = &x;
}
else {
x+size = &a
size++;
}
}
}
void expand() {
//create a new array
size = size + 1;
T *x[size+1000];
for (int a = 0; a < size; a++) {
*x[a] = *s[a];
}
}
void del(int i) {
if (i > this->size || i <size)
throw new Set_Exception ("Index out of bounds");
else
delete s+i+1;
size--;
}
//union of 2 sets
T operator+ (T a) {
T t;
//create pointers to point to a copied version of "this" and "a" so we can traverse them
T x, y;
x = this;
y = a;
T *x1, *x2;
x1 = x;
x2 = y;
for (int outter = 0; outter < this->size; outter++) {
for (int inner = 0; inner < a.size; inner++) {
if (*x1 != *x2) {
//this->*s(outter) exists in a.s(inner) don't add that to t
t.add(x1);
t.size = size + 1;
}
++x1;
}
++x2;
}
//once the loop is exited that means all the elements common in this.s and a.s have been added so now just add all elements in a.s
//reassignt x2
x2 = y;
for (int x = 0; x < a.size; x++) {
t.add(*x2);
t.size = size + 1;
++x2
}
return t;
}
//intersection of 2 sets
T operator/ (T a) {
T t;
T x, y;
x = this;
y = a;
T *x1, *x2;
x1 = x;
x2 = y;
for (int outter = 0; outter < this->size; outter++) {
for (int inner = 0; inner < a.size; inner++) {
if (*(x1 + outter) == *(x2 + inner))
//this->*s(outter) exists in a.s(inner) so add that to t
t.add(*x2);
//++x1;
}
//++x2;
}
//once the loop is exited that means all the elements common in both sets have been added to t
return t;
}
//the product of 2 sets
T operator* (T a) {
T t;
//create pointers to point to a copied version of "this" and "a" so we can traverse them
T x, y;
x = this;
y = a;
T *x1, *x2;
x1 = x;
x2 = y;
//test condition
if (this->size != a.size) {
cout << "This cannot be done, the sets differ in size" << endl;
else
for (int loop = 0; loop < a.size; loop++) {
t.add(*x1 * *x2);
++x1;
++x2;
}
}
return t;
}
//subtaction of intersecting parts
T operator- (T a) {
}
friend void friendly_print(const Set<T>*);
};
template <class T>
void friendly_print(const Set <T> *X) {
for (int x = 0; x < X->size; x++) {
cout << "{" X->s << ", ";
}
cout << "}" << endl;
}
template <class T1, class T2> class Pair {
private:
T1 a;
T2 b;
public:
Pair () {
a = 0;
b = 0;
}
Pair (T1 x, T2 y) {
a = x;
b = y;
}
friend ostream& operator<<(ostream&, const Pair<T1, T2>&);
};
template <class T1, class T2>
ostream& operator<<(ostream& os,const Pair<T1,T2>& p) {
os << p.a<<" "<<p.b<<" "<<endl;
return os;
}
class Set_Exception {
private:
string message;
public:
Set_Exception() {
message = "";
}
Set_Exception(string m) {
message = m;
}
void print() {
cout << message;
}
};
void main() { //~~~line 233
Set<int> A;
A.add(5); A.add(14); A.add(3); A.add(7); A.add(87); A.add(106);
try {
A.add(3);
}
catch (Set_Exception& e) {
e.print(); // must print to the screen (adding an existing element to the set)
}
A.del(1); // remove the first element in the set A
A.del (3); //remove the 3rd element in the set A
try {
A.del(-2);
}
catch (Set_Exception& e) {
e.print(); //must print to the screen (trying to delete using an out of bound index)
}
try {
A.del(20);
}
catch (Set_Exception& e) {
e.print(); //must print to the screen (trying to delete using an out of bound index)
}
int integer_list[10] = {3, 45, 67, 25, 64, 89, 36, 5, 106, 460};
Set <int> B(integer_list, 10);
Set<int> C1, C2, C3;
Set<Pair<int, int>> C4; //~~~line 266
C1 = A / B; //~~~~error C2679: binary '/' : no operator defined which takes //a right-hand operand of type 'class Set<int>' (or there is no acce
ptable conversion)
friendly_print (C1); // must print { 3, 5, 106}
C2= A + B;
friendly_print (C2); // must print { 5, 14, 3, 7, 87, 106, 45, 67, 25, 64, 89, 36, 5, 106, 460}
C3= A - B;
friendly_print (C3); // must print {14, 7, 87}
C4= C1 * C3; //~~~error C2679: binary '*' : no operator defined which takes a right-hand operand of type 'class Set<int>' (or there is no acce
ptable conversion)
friendly_print (C4); // must print {(3,14),(3,7),(3,87),(5,14),(5,7),(5,87),(106,14),(106,7),(106, 87)}
Char character_list[4] = {'a', 'f', 't', 'j'} //~~line 278
set <char> U(character_list, 4);
set <char> V();
V.add('a'); V.add('n'); V.add(f);
Set<char> D1, D2, D3;
Set< Pair<char, char> > D4; //~~~~error C2146: syntax error : missing ',' before identifier 'C4'
friendly_print (D1); //print {}
D1 = U \ V;
friendly_print(D1); // print {a, f} ~~~~~error C2784: 'void __cdecl //friendly_print(const class Set<T> *)' : could not deduce template argument //for 'const class Set<T> *' from 'class Set<int>'
D2 = U + V;
friendly_print(D2); // print {a, f, t, j, n}
D3 = U - V;
friendly_print (D3);// print {n}
D4 = D1 * D3;
friendly_print (D4); // print {(a,n), (f,n)}
if (U == U) cout << "U and V are equal" << endl; //line~~~~line 298
else cout << " U and V are not equal" << endl;
cout << "the second element in U is : " << U[2] << endl;
try {
cout << "the tenth element in U is : " << U[10] << endl;
}
catch (exception e) {
cout << "out of bound access" << endl;
}
Set<char> * set_ptr = new Set<char>();
set_ptr->add('d');
delete set_ptr; // must print (Set destructor is called)
}
Code:
--------------------Configuration: Assignment3 - Win32 Debug--------------------
Compiling...
Assignment3Test2.cpp
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(266) : error C2146: syntax error : missing ',' before identifier 'C4'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(266) : error C2065: 'C4' : undeclared identifier
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(266) : error C2143: syntax error : missing '>' before ';'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(268) : error C2679: binary '/' : no operator defined which takes a right-hand operand of type 'class Set<int>' (or there is no acce
ptable conversion)
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(269) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<int>'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(270) : error C2679: binary '+' : no operator defined which takes a right-hand operand of type 'class Set<int>' (or there is no acce
ptable conversion)
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(271) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<int>'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(272) : error C2679: binary '-' : no operator defined which takes a right-hand operand of type 'class Set<int>' (or there is no acce
ptable conversion)
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(273) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<int>'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(274) : error C2679: binary '*' : no operator defined which takes a right-hand operand of type 'class Set<int>' (or there is no acce
ptable conversion)
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(278) : error C2065: 'Char' : undeclared identifier
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(278) : error C2146: syntax error : missing ';' before identifier 'character_list'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(278) : error C2065: 'character_list' : undeclared identifier
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(278) : error C2109: subscript requires array or pointer type
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(278) : error C2059: syntax error : '{'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(278) : error C2143: syntax error : missing ';' before '{'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(278) : error C2143: syntax error : missing ';' before '}'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(279) : error C2065: 'set' : undeclared identifier
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(279) : error C2062: type 'char' unexpected
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(280) : error C2062: type 'char' unexpected
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(281) : error C2065: 'V' : undeclared identifier
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(281) : error C2228: left of '.add' must have class/struct/union type
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(281) : error C2228: left of '.add' must have class/struct/union type
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(281) : error C2228: left of '.add' must have class/struct/union type
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(281) : error C2065: 'f' : undeclared identifier
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(287) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<char>'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(289) : error C2017: illegal escape sequence
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(289) : error C2065: 'U' : undeclared identifier
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(289) : error C2146: syntax error : missing ';' before identifier 'V'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(290) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<char>'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(291) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conv
ersion)
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(292) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<char>'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(293) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conv
ersion)
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(294) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<char>'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(295) : error C2679: binary '*' : no operator defined which takes a right-hand operand of type 'class Set<char>' (or there is no acc
eptable conversion)
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(296) : error C2784: 'void __cdecl friendly_print(const class Set<T> *)' : could not deduce template argument for 'const class Set<T
> *' from 'class Set<class Pair<char,char> >'
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(301) : error C2109: subscript requires array or pointer type
D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\CSI2172 - C++\1Assignments\Assignment3Test2.cpp(304) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
Assignment3Test2.obj - 38 error(s), 0 warning(s)
|