C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help creating a 3d Vector class Posted by chrysalisx on 16 May 2006 at 8:20 PM
Here's the basics. I'm trying to create a vector class with all the functionality of a regular vector but with 2 simple changes to accomidate refrencing it as though it were at 3D array. If there is an easier way to do this, let me know.
1: the at(int) function will be overloaded to handle at(int,int,int)
2: there will be 3 private ints to keep track of xSize, ySize, and zSize, as well as appropriate accessor and mutator functions.

Seems easy right? wrong. I've run into problems up the wazoo. Previously I had implemented the functions in a .cpp file, but that caused memory errors. In it's current form, it doesn't crash, but when I create a new Vector3d, it complains whenever I try and use a function that SHOULD be inhereted from std::vector. Am I just declaring this wrong or what? Help!!!

FILE:Vector3d.h

#include <vector>
using namespace std;

template <class T>
class Vector3d : public std::vector<T> {
public:
Vector3d();
Vector3d(int xSize, int ySize, int zSize);
T at(int x, int y, int z){
return this->vector<T>::at( (x) + (y*myXsize) + (z*myXsize*myYsize) );
};
void setDimensions(int xSize, int ySize, int zSize){
if(this->capacity() < xSize*ySize*zSize){
this->resize(xSize*ySize*zSize);
}
myXsize = xSize;
myYsize = ySize;
myZsize = zSize;
}
void setDimensions(int cubeSize){
if(this->capacity() < cubeSize^3){
this->resize(cubeSize^3);
}
myXsize = cubeSize;
myYsize = cubeSize;
myZsize = cubeSize;
}

//Accessor
int xSize(void){ return myXsize; }
int ySize(void){ return myYsize; }
int zSize(void){ return myZsize; }

private:
int myXsize;
int myYsize;
int myZsize;
};
Report
Re: Help creating a 3d Vector class Posted by bosebonas on 22 May 2006 at 6:20 AM
: Here's the basics. I'm trying to create a vector class with all the functionality of a regular vector but with 2 simple changes to accomidate refrencing it as though it were at 3D array. If there is an easier way to do this, let me know.
: 1: the at(int) function will be overloaded to handle at(int,int,int)
: 2: there will be 3 private ints to keep track of xSize, ySize, and zSize, as well as appropriate accessor and mutator functions.
:
: Seems easy right? wrong. I've run into problems up the wazoo. Previously I had implemented the functions in a .cpp file, but that caused memory errors. In it's current form, it doesn't crash, but when I create a new Vector3d, it complains whenever I try and use a function that SHOULD be inhereted from std::vector. Am I just declaring this wrong or what? Help!!!
:
: FILE:Vector3d.h
:
: #include <vector>
: using namespace std;
:
: template <class T>
: class Vector3d : public std::vector<T> {
: public:
: Vector3d();
: Vector3d(int xSize, int ySize, int zSize);
: T at(int x, int y, int z){
: return this->vector<T>::at( (x) + (y*myXsize) + (z*myXsize*myYsize) );
: };
: void setDimensions(int xSize, int ySize, int zSize){
: if(this->capacity() < xSize*ySize*zSize){
: this->resize(xSize*ySize*zSize);
: }
: myXsize = xSize;
: myYsize = ySize;
: myZsize = zSize;
: }
: void setDimensions(int cubeSize){
: if(this->capacity() < cubeSize^3){
: this->resize(cubeSize^3);
: }
: myXsize = cubeSize;
: myYsize = cubeSize;
: myZsize = cubeSize;
: }
:
: //Accessor
: int xSize(void){ return myXsize; }
: int ySize(void){ return myYsize; }
: int zSize(void){ return myZsize; }
:
: private:
: int myXsize;
: int myYsize;
: int myZsize;
: };
:
hi my friend,
i can see that you should try and look CAREFULLY at your accesors and the way you manage pointer variables.don t forget you are in front of a class.if you need the code of the class that is completely functionnal then contact me.tell me also as accurately as possible the specifications of this class,from how it has to wark to the explanation of all its data members and memeber functions.
bye ,good coding..
bye.

Report
Re: Help creating a 3d Vector class Posted by WerewolfWare on 23 May 2006 at 5:30 AM
What's the use for capacity()?
Report
Re: Help creating a 3d Vector class Posted by bosebonas on 23 May 2006 at 7:21 AM
hi my friend,
please send me the specifications of your vector class,that is the data memebers and the memeber functions.but please if you can give the details about the memeber functions for me to start working on the class can be of great help to you.
good coding. bye.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.