Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 13th, 2006, 8:53 PM   #1
RemoteC2
Programmer
 
RemoteC2's Avatar
 
Join Date: Jan 2006
Posts: 55
Rep Power: 3 RemoteC2 is on a distinguished road
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;
}
RemoteC2 is offline   Reply With Quote
Old Aug 13th, 2006, 9:14 PM   #2
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0 King is an unknown quantity at this point
getx() and setx() are methods that are apart of the class vArray. You are trying to go:
arrayName[i].setx(arrayName[i]);
setx() is not part of a char*, it's a part of your class, you can't just tac that function on the back of anything you want.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Aug 13th, 2006, 9:16 PM   #3
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
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.
Game_Ender is offline   Reply With Quote
Old Aug 13th, 2006, 9:23 PM   #4
RemoteC2
Programmer
 
RemoteC2's Avatar
 
Join Date: Jan 2006
Posts: 55
Rep Power: 3 RemoteC2 is on a distinguished road
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
RemoteC2 is offline   Reply With Quote
Old Aug 13th, 2006, 9:33 PM   #5
RemoteC2
Programmer
 
RemoteC2's Avatar
 
Join Date: Jan 2006
Posts: 55
Rep Power: 3 RemoteC2 is on a distinguished road
okay, now i see what i was doing wrong =)
RemoteC2 is offline   Reply With Quote
Old Aug 13th, 2006, 9:33 PM   #6
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 376
Rep Power: 0 King is an unknown quantity at this point
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;
}
If you do want a class, try this:
#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;
}
Hope this clears things up a bit for you.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Aug 13th, 2006, 9:46 PM   #7
RemoteC2
Programmer
 
RemoteC2's Avatar
 
Join Date: Jan 2006
Posts: 55
Rep Power: 3 RemoteC2 is on a distinguished road
wow..much easier i thank everyone for the help, this has really aided me
RemoteC2 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB 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
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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:55 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC