Errors help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Errors help

 
0
  #1
Dec 18th, 2005
i have errors and i dont know y im gettin them here is the code. a majority of them are undeclaired idetifyers but they are function calls?!?!

  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. class Array
  7. {
  8. public:
  9. Array();
  10. Array(const Array& copyFrom);
  11. ~Array() { };
  12. void append(int arrayA[]);
  13. void chop(int arrayA[]);
  14. void print(int arrayA[], int arrayB[], int arrayC []);
  15. void values(int arrayA[], int arrayB[], int *ptr);
  16. void is_equal(int arrayA[], int arrayB[], int arrayC[]);
  17.  
  18. private:
  19. int add,
  20. subtract;
  21. };
  22.  
  23.  
  24. void main()
  25. {
  26.  
  27. int arrayA[5] = {1,2,3,4,5},
  28. arrayB[7] = {1,2,3,4,5,0,0},
  29. arrayC[5] = {1,2,3,4,5};
  30. int copyFrom;
  31.  
  32. Array();
  33. Array(Array& copyFrom);
  34. values(arrayA[5]);
  35. print(arrayA[5], arrayB[7], arrayC[5]);
  36.  
  37. append(arrayA[5]);
  38. print(arrayA[5], arrayB[7], arrayC [5]);
  39.  
  40. chop(arrayA[5]);
  41.  
  42. print(arrayA[5], arrayB[7], arrayC[5]);
  43. cout << "Check to see if any array's are equal" << endl;
  44.  
  45. is_equal(arrayA[5], arrayB[7], arrayC[5]);
  46. }//main
  47.  
  48. Array::Array()
  49. {
  50. int *ptr = 0;
  51. }
  52.  
  53. Array::Array(const Array& copyFrom)
  54. {
  55. int arrayA[5] = copyFrom.arrayA[5];
  56.  
  57. }// end copy
  58.  
  59. void Array::append(int arrayA[])
  60. {
  61.  
  62. cout<<"Enter the number you are inserting\n\n";
  63. cin>> add;
  64.  
  65. cout << "We will insert " << add << " into Array A\n" << endl;
  66.  
  67. arrayA[5-1] = add;
  68.  
  69.  
  70. }//end append
  71.  
  72. void Array::chop(int arrayA[])
  73. {
  74. cout << "Now we will delete that value from the Array" << endl;
  75.  
  76.  
  77.  
  78.  
  79.  
  80. }
  81.  
  82. void Array::values(int arrayA[], int arrayB[], int *ptr)
  83. {
  84. *this = arrayA[5];
  85. *ptr = arrayB[7];
  86.  
  87. }// end values
  88.  
  89. void Array::print(int arrayA[], int arrayB[], int arrayC [])
  90. {
  91. cout << "Array A is: " << endl;
  92. for(int i = 0; i < 5; i++)
  93. cout << arrayA[i] << " ";
  94. cout << "\n\n";
  95.  
  96. cout << "Array B is: " << endl;
  97. for(int j = 0; j < 7; j++)
  98. cout << arrayB[j] << " ";
  99. cout << "\n\n";
  100.  
  101. cout << "Array C is: " << endl;
  102. for(int k = 0; k < 5; k++)
  103. cout << arrayC[k] << " ";
  104. cout << "\n\n";
  105. }//print
  106.  
  107.  
  108. void Array::is_equal(int arrayA[], int arrayB[], int arrayC[])
  109. {
  110.  
  111.  
  112. for(int i = 0; i < 5; i++)
  113. cout << arrayA[i] << " ";
  114. cout << endl;
  115. for(int j = 0; j < 7; j++)
  116. cout << arrayB[j] << " ";
  117. cout << endl;
  118.  
  119. if(arrayA[i] == arrayB[j])
  120. cout << "True" << endl;
  121. else
  122. cout << "False" << endl;
  123.  
  124.  
  125.  
  126. for (i = 0; i < 5; i++)
  127. cout << arrayA[i] << " ";
  128. cout << endl;
  129. for( j = 0; j < 5; j++)
  130. cout << arrayC[j] << " ";
  131. cout << endl;
  132.  
  133. if(arrayA[i] == arrayC[j])
  134. cout << "True" << endl;
  135. else
  136. cout << "False" << endl;
  137.  
  138. }
  139.  
  140. Array::~Array()
  141. {
  142. delete arrayA;
  143.  
  144. }//destructor
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Errors help

 
0
  #2
Dec 18th, 2005
  1. void main()
That is the first problem -- it must be
  1. int main()

Please identifiy other errors you are getting so that we don't have to compile your code. List some of the errors.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: Errors help

 
0
  #3
Dec 18th, 2005
im gettin errors saying that the function calls in the main are undeclaired identifyers
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Errors help

 
0
  #4
Dec 18th, 2005
Uh, you need some variable names here:

Array();
Array(Array& copyFrom);

like:

Array myArray;
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: Errors help

 
0
  #5
Dec 18th, 2005
here are the errors that im gettin with the part that it points to below it, some have arrows pointing to specific parts.

any help on these would be awsome cause i dont get y im gettin function calls as undeclaired identifyers

error C2275: 'Array' : illegal use of this type as an expression
see declaration of 'Array'
Array(Array& copyFrom);

error C2065: 'values' : undeclared identifier
values(arrayA[5]);

error C2065: 'print' : undeclared identifier
print(arrayA[5], arrayB[7], arrayC [5]);

error C2065: 'append' : undeclared identifier
append(arrayA[5]);

error C2065: 'chop' : undeclared identifier
chop(arrayA[5]);


error C2065: 'is_equal' : undeclared identifier
is_equal(arrayA[5], arrayB[7], arrayC[5]);

error C2039: 'arrayA' : is not a member of 'Array'
see declaration of 'Array'
Array::Array(const Array& copyFrom)
{
-> int arrayA[5] = copyFrom.arrayA[5];

}// end copy

error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
void Array::values(int arrayA[], int arrayB[], int *ptr)
{
-> *this = arrayA[5];
*ptr = arrayB[7];

}// end values
error C2084: function '__thiscall Array::~Array(void)' already has a body
Array::~Array()
-> {


}//destructor
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Errors help

 
0
  #6
Dec 18th, 2005
1. Array() by itself if not a valid statement. If you want to create an object of type Array, then give it a name. The code snippet below instantiates an object of class Array and names is obj.
  1. Array obj;

After you have named the object you can use its methods by stating the object name followed by a dot and then by the method name. Pay close attention to the function parameters -- their type must match the number of parameters and data type in the class description.
  1. Array obj;
  2. ...
  3. int aptr;
  4. obj.values(arrayA, arrayB, &aptr);

Most of the errors you posted seem to be pretty clear about what is wrong. The error gives you the line number and what is wrong. Look at the code and you should be able to determine the cause of the error. Youre compiler's documentation will also normally give you a more elaborate explaination of the error number.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: Errors help

 
0
  #7
Dec 19th, 2005
ok so after lookin up a couple other function programs i did i found out that it was somethin stupid i forgot so dont worry about thoes errors now the only errors im gettin are

'values' : cannot convert parameter 1 from 'int' to 'int []'

for example but im gettin that same thing for every function. i never understand these errors

and this one

error C2084: function '__thiscall Array::~Array(void)' already has a body

my first time using destructors so i dunno what that means
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: Errors help

 
0
  #8
Dec 19th, 2005
Originally Posted by Ancient Dragon
1. Array() by itself if not a valid statement. If you want to create an object of type Array, then give it a name. The code snippet below instantiates an object of class Array and names is obj.
  1. Array obj;

After you have named the object you can use its methods by stating the object name followed by a dot and then by the method name. Pay close attention to the function parameters -- their type must match the number of parameters and data type in the class description.
  1. Array obj;
  2. ...
  3. int aptr;
  4. obj.values(arrayA, arrayB, &aptr);

Most of the errors you posted seem to be pretty clear about what is wrong. The error gives you the line number and what is wrong. Look at the code and you should be able to determine the cause of the error. Youre compiler's documentation will also normally give you a more elaborate explaination of the error number.
yea thats what i found i did wrong when i looked back

but man i didnt know i have something that explains errors more how do i get tp the compiler documentation?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Errors help

 
0
  #9
Dec 19th, 2005
It appears that you may be using Microsoft Visual C++ -- all their errors are explained at www.msdn.microsoft.com. Just enter the error number in the search block.
  1. error C2084: function '__thiscall Array::~Array(void)' already has a body

That means the destructor has already been coded, either as an inline function in the header file or in the implementation file. In your case it was already defined in the header. If you want it in the implementation file you have to remove the braces shown in RED below.
~Array() { };

When the function requires an array, all you have to do is put the array's name in the parameter list, as shown in main() in this code snipet.
int foo( int array[] )
{
  // do something
}

int main()
{
   int array[10];
   foo(array);
}
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: Errors help

 
0
  #10
Dec 19th, 2005
wow that error thing made my life so much easier thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC