![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
viewing contents of array
the object of the class that i made was to get the contents of a target array..this can only handle arrays with numbers so far, but that is not my problem..my problem is that i get the following errors after i compile this program:
G:\Secondary\Dev-Cpp\SOURCES\Chapter 14\vArray.cpp In member function `void vArray::getArray(char*, int)': 13 G:\Secondary\Dev-Cpp\SOURCES\Chapter 14\vArray.cpp `setx' is not a type 13 G:\Secondary\Dev-Cpp\SOURCES\Chapter 14\vArray.cpp request for member of non-aggregate type before '(' token 14 G:\Secondary\Dev-Cpp\SOURCES\Chapter 14\vArray.cpp `getx' is not a type 14 G:\Secondary\Dev-Cpp\SOURCES\Chapter 14\vArray.cpp request for member of non-aggregate type before '(' token i really dont know what any of these mean so can someone please help me? this is the code: #include <iostream>
using namespace std;
class vArray
{
int x;
int i;
public:
int getx() {return x;}
void setx (int i) {x=i;}
void getArray(char *arrayName, int arraySZ) {
for(i=0; i<arraySZ; i++) {
arrayName[i].setx(arrayName[i]);
cout<<arrayName[i].getx();
}
}
}vA;
int main ()
{
return 0;
} |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0
![]() |
getx() and setx() are methods that are apart of the class vArray. You are trying to go:
arrayName[i].setx(arrayName[i]);
__________________
I am Addicted to Linux! |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
arrayName[i] will return a char. char is a built in type, it does not have functions called setx, and getx. It looks like you have yourself a bit confused here. What is it you are trying to do.
Edit: Beat to it by King. Last edited by Game_Ender; Aug 13th, 2006 at 9:27 PM. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
i am trying to make a class that has a main function (getArray), and in getArray, it will return the contents of the target array (getArray(char *arrayName, int arraySZ)). i am a little bit confused as to what to do, but that is why i am here
i hope that answered your question |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
okay, now i see what i was doing wrong =)
|
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0
![]() |
You don't really need a whole class just for this, a function would do just fine, take a look at this:
#include <iostream>
using namespace std;
void PrintArray(char* myArray[100])
{
for(int i = 0; i != sizeof(myArray); ++i)
{
cout << myArray[i] << endl;
}
}
int main ()
{
char* myArray[100] = {"t", "e", "s", "t"};
PrintArray(myArray);
return 0;
}#include <iostream>
using namespace std;
class Array
{
public:
Array()
{
}
void PrintArray(char* myArray[100])
{
for(int i = 0; i != sizeof(myArray); ++i)
{
cout << myArray[i] << endl;
}
}
};
int main ()
{
char* myArray[100] = {"t", "e", "s", "t"};
Array classArray;
classArray.PrintArray(myArray);
return 0;
}
__________________
I am Addicted to Linux! |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
wow..much easier
i thank everyone for the help, this has really aided me |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| changing size of an array | Eric the Red | Java | 3 | Apr 3rd, 2006 8:19 PM |
| Displaying contents of an array | Wizard1988 | Assembly | 3 | Oct 12th, 2005 9:15 PM |
| How To Split Array Into Two Seperate Arrays? | blackmagic | Perl | 1 | Apr 30th, 2005 2:16 PM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 2:36 AM |
| Converting 1-dimensional array to 2-dimensional array | Tazz_Mission_13 | Java | 6 | Apr 8th, 2005 11:58 AM |