Help creating a 3d Vector class - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help creating a 3d Vector class

chrysalisxchrysalisx Posts: 1Member
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
using namespace std;

template
class Vector3d : public std::vector {
public:
Vector3d();
Vector3d(int xSize, int ySize, int zSize);
T at(int x, int y, int z){
return this->vector::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;
};

Comments

  • bosebonasbosebonas Posts: 87Member
    : 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
    : using namespace std;
    :
    : template
    : class Vector3d : public std::vector {
    : public:
    : Vector3d();
    : Vector3d(int xSize, int ySize, int zSize);
    : T at(int x, int y, int z){
    : return this->vector::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.

  • WerewolfWareWerewolfWare Posts: 304Member
    What's the use for capacity()?
  • bosebonasbosebonas Posts: 87Member
    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.
Sign In or Register to comment.