GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Dec-2004, 14:56
mattchew008 mattchew008 is offline
New Member
 
Join Date: Nov 2004
Posts: 11
mattchew008 is on a distinguished road

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!

CPP / C++ / C Code:
#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)
  #2  
Old 05-Dec-2004, 23:31
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Are you expecting someone to read all of that? Good luck...
__________________
-Aaron
  #3  
Old 19-Dec-2004, 06:06
dexter dexter is offline
Junior Member
 
Join Date: Jul 2004
Location: Queensland, Australia
Posts: 39
dexter will become famous soon enough
Your biggest problems are...
  1. Your commenting is extremely bare.
  2. You need meaningful variable names.
  3. Your spacing and layout is not easy to read. (maybe for you, yes, but others, no)
  4. Has no-one ever told you about meaningful variable names?
  5. You haven't even looked for basic syntax errors to begin with... e.g missing ';' that I found when cleaning up the code... (what can I say, I'm bored).
  6. What the classes are supposed to do...
  7. Meaningful variable names.

I could probably find more... but that'll do for now...

EDIT: Had a look, you're coding style is horrific... so it's absolutely impossible to tell what on earth you're trying to do...

Though, this piece in main() stands out:

CPP / C++ / C Code:
Set<Pair<int, int>> C4;

Most likely you need to create you're class to be able to use type Pair, as opposed to trying to use it via templates. Templates are only so good...
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Lists advice request promsan C Programming Language 74 23-May-2007 08:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 11:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 10:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30
C++ PhoneBook marita C++ Forum 46 12-Jun-2005 12:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:12.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.