| | |
pair
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
I want to do like this, but how to call from i=0, i<11; i++, and how o insert in this program.
C++ Syntax (Toggle Plain Text)
#include <iostream.h> template<class C> class Pair { public: Pair(C, C); Pair(Pair&); void Display(); private: C first; C second; }; template<class C> Pair<C>::Pair(C left, C right) { first = left; second = right; } template<class C> Pair<C>::Pair(Pair<C>& p) { first = p.first; second = p.second; } template<class C> void Pair<C>::Display() { cout<<"(" << first <<","<< second <<")"<<"\n"; } int main() { Pair<int> pi(2,3); pi.Display(); return 0; }
•
•
Join Date: Mar 2008
Posts: 62
Reputation:
Solved Threads: 7
Well since you want to do it in a for loop, you must realize that this is probably a job for pointers since you can't make a for loop generate names for your variables to hold the class. What I would do is this:
C++ Syntax (Toggle Plain Text)
int main() { const int SIZE = 8; Pair<int> * pairs[SIZE]; // Declare an array of pointers to Pair<int> for (int i = 0; i < SIZE; i++) pairs[i] = new Pair<int>(1,i); // Construct each new pair and give its address to an index in the pointer array pairs[3]->Display(); //since Display is a member function of an object, and pairs[num] is a pointer to that object, you use the arrow operator to dereference and call the member function return 0; }
•
•
Join Date: Mar 2008
Posts: 62
Reputation:
Solved Threads: 7
If you do not understand what pointers are or how they work, it would not be fitting to describe every aspect of them in this thread.
I will however give you a good tutorial on pointers, and when you practice with their examples, you should have a decent grasp of them, then you may come back to the example I gave previously and it should seem more clear.
http://www.cplusplus.com/doc/tutorial/pointers.html
I will however give you a good tutorial on pointers, and when you practice with their examples, you should have a decent grasp of them, then you may come back to the example I gave previously and it should seem more clear.
http://www.cplusplus.com/doc/tutorial/pointers.html
I understand now, but a lot of error.
error C2065: 'pairs' : undeclared identifier
error C2109: subscript requires array or pointer type
error C2061: syntax error : identifier 'Pair'
error C2109: subscript requires array or pointer type
error C2227: left of '->Display' must point to class/struct/union
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : fatal error C1003: error count exceeds 100; stopping compilation
Error executing cl.exe.
78.exe - 102 error(s), 0 warning(s)
error C2065: 'pairs' : undeclared identifier
error C2109: subscript requires array or pointer type
error C2061: syntax error : identifier 'Pair'
error C2109: subscript requires array or pointer type
error C2227: left of '->Display' must point to class/struct/union
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\ashida\My Documents\MASTER C++\main\78.cpp(22) : fatal error C1003: error count exceeds 100; stopping compilation
Error executing cl.exe.
78.exe - 102 error(s), 0 warning(s)
Here it is..
C++ Syntax (Toggle Plain Text)
#include <iostream> usingnamespace std; { const int students.size = 12; Pair<int> * pairs[students.size]; // Declare an array of pointers to Pair<int> for (int i = 0; i < students.size; i++) pairs[i] = new Pair<int>(1,i); // Construct each new pair and give its address to an index in the pointer array pairs[3]->Display(); //since Display is a member function of an object, and pairs[num] is a pointer to that object, you use the arrow operator to dereference and call the member function return 0; }
•
•
Join Date: Mar 2008
Posts: 62
Reputation:
Solved Threads: 7
1.
Did you make sure you kept what you had in front of main? I remove that from the code i posted as it is the same as you had, only the things in main were what i changed.
2.
students.size is referring to a data member of an object that doesn't exist. Moreover, since it would be a data member inside an object, it couldn't be declared again. Use a plain variable name instead of students.size. maybe students_size
Did you make sure you kept what you had in front of main? I remove that from the code i posted as it is the same as you had, only the things in main were what i changed.
2.
students.size is referring to a data member of an object that doesn't exist. Moreover, since it would be a data member inside an object, it couldn't be declared again. Use a plain variable name instead of students.size. maybe students_size
This is a full code. but error.fatal error C1003: error count exceeds 100; stopping compilation
Error executing cl.exe.
is it cannot exceed 100?
Error executing cl.exe.
is it cannot exceed 100?
C++ Syntax (Toggle Plain Text)
/*------------------------------------------------------------------------------------------+ | Filename : ConflictMatrix.cpp | +------------------------------------------------------------------------------------------*/ #include <iostream> // std::cout #include <fstream> #include <iomanip> #include <string> // std::string #include <vector> // std::vector<> #include <algorithm> //std::for each() using namespace std; // import "std" namespace into global namespace struct student { string studentid; vector <int> examcode; }; int main() { ifstream stream1 ("STA83STU.txt"); if ( !stream1 ) { cout << "While opening a file an error is encountered" << endl; } else { cout << "File is successfully opened" << endl; } vector <student> students; student aStudent; string tempStudentID; bool readEntireFile = false; // set to true when reach end of file stream1 >> tempStudentID; // read in student id of first student while ( !readEntireFile ) { aStudent.studentid = tempStudentID; // new student int tempExamCode; aStudent.examcode.clear (); stream1 >> tempExamCode; // read in first exam code for this student aStudent.examcode.push_back (tempExamCode); // add this exam code to current student's vector of exam codes bool newStudent = false; // true when a new student id is encountered while ( !newStudent && !readEntireFile ) { if ( stream1 >> tempStudentID ) // successfully read in student id { if ( tempStudentID.compare (aStudent.studentid) == 0 ) // student id is same as before { stream1 >> tempExamCode; // read in exam code aStudent.examcode.push_back (tempExamCode); // add this exam code to this student;s vector of exam codes } else newStudent = true; // student id is different from before. Therefore new student. } else readEntireFile = true; // end of file reached. Want to exit inner and outer while loops } // if new student, do not repeat this while loop students.push_back (aStudent); // no more exam codes for this student. Add aStudent to students vector } stream1.close (); // We have read the entire file, so time to close it. for ( int i = 0 ; i < students.size (); i++ ) { cout <<i<<":\t" ; // output student id for ( int j = 0;j<students.at(i).examcode.size(); j++ ) cout << students.at (i).examcode.at(j) <<"\t"; // output list of exam codes for this student cout<<""<<"\n"; } /*--------------------------------------------------------------------------------------------+ | counting elements in StudentID | +--------------------------------------------------------------------------------------------*/ { const int student_size = 12; Pair<int> * pairs[student_size]; // Declare an array of pointers to Pair<int> for (int i = 0; i < student_size; i++) pairs[i] = new Pair<int>(1,i); // Construct each new pair and give its address to an index in the pointer array pairs[3]->Display(); //since Display is a member function of an object, and pairs[num] is a pointer to that object, you use the arrow operator to dereference and call the member function return 0; } /*-------------------------------------------------------------------------------------------+ | Matrix ExamID +--------------------------------------------------------------------------------------------*/ { cout<<"i,j|"; for (int colHead = 1; colHead < 11; colHead++) cout << setw(3) << colHead; cout << endl; cout <<"__________________________________"<<endl; for (int rowVal = 1; rowVal < 11; rowVal++) { cout << setw(3)<< rowVal <<'|'; for (int colVal =1; colVal < 11; colVal++) cout << setw(3)<<"x"; cout <<endl; } } }
![]() |
Similar Threads
- using Lua's pair() (Python)
- Dictionary -- key:value pair swap (Python)
- Last CLASS method needs help... PAIR::area() (C++)
- Cannot get PAIR::big to just display greater number (C++)
- write a program that simulates rooling a pair of dice. (Java)
- New look (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: binary search tree find
- Next Thread: Constructor parameters
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





