LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2004, 12:52 AM   #1
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Rep: Reputation: 30
STL vector of 3 doubles?


is it possible to create an STL vector of 3 doubles? i cant find much documentation of it. if so, how do you access each one seperately?? basicaly, i need to change this to a stl vector

Code:
struct Vector {
  float x;
  float y;
  float z;
};
thanks
 
Old 04-22-2004, 04:37 AM   #2
cjp
Member
 
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Rep: Reputation: 15
I think that you are confused by the name vector. Your Vector struct clearly describes a three-dimensional geometric vector. Informatics-people use the word vector as a synonym for "array". Actually, the STL vector class is an array container class. If you REALLY want to implement your Vector op top of the STL vector, I'd do this:
Code:
#include <vector>

class Vector : protected std::vector<double>
{
    Vector()
    {push_back(0.0); push_back(0.0); push_back(0.0);} //allocate three elements

    double &x(){return (*this)[0];}
    double &y(){return (*this)[1];}
    double &z(){return (*this)[2];}

};
 
Old 04-22-2004, 10:13 AM   #3
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Original Poster
Rep: Reputation: 30
no, im not confused... it is a exersize we must do for an assignment. we also had to change a simple array to an STL vector... but thanks, that will work
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
point / STL vector, change element question true_atlantis Programming 1 09-17-2005 01:46 PM
ATI Mobility Radeon 9000 doubles game speed ichi Linux - Software 1 07-31-2005 06:27 AM
can i modify int 80 vector to a user-defined vector qqrilxk Linux - Security 1 03-03-2005 08:46 PM
Miseries at install from HDD&floppies, with vector ISO& how to boot with vector linux prctom VectorLinux 9 06-29-2004 05:27 AM
Vector(STL) question(push_back & erase) Ohmu Programming 1 01-29-2004 04:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration