473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

c++ vectors simple question

I've come to a point where I must question everything, maybe you can help...

if

Expand|Select|Wrap|Line Numbers
  1. vector<object*> ptr_vec;
is a vector of pointers where all objects of ptr_vec have public member variables:

Expand|Select|Wrap|Line Numbers
  1.  mem_var1 = somenumber; 
  2. mem_var2 = somenumber;
  3.  
using:

Expand|Select|Wrap|Line Numbers
  1. int i = somenumber; 
as a number less than or equal to the size of the vector, is:

Expand|Select|Wrap|Line Numbers
  1. int j = (ptr_vec[i] -> mem_var1) %!@% i;
considered defined behavior for %!@% a standard operation *, /, +, or -?

what about:

Expand|Select|Wrap|Line Numbers
  1. ptr_vec[i] -> mem_var1 = ptr_vec[i] ->memvar2 %!@% i;
for the same operations?
Apr 16 '06 #1
2 2197
Banfa
9,065 Expert Mod 8TB
You do not seem to have stated a real problem or an actual question.

I have considered the lines of code you have posted, what would you like me to do next?
Apr 18 '06 #2
yeah, sorry, dumb question. I've just been looking into undefined behavior, and I know that pointers in vectors can cause a lot of problems. thanks for your time.
Apr 19 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ataru | last post by:
My boss has some beef or other with vectors - he says that they've given him trouble over the years, and so he uses some template classes he wrote 15 years ago. My question is, is the standard...
12
by: Dave Theese | last post by:
Hello all, I'm in a poition of trying to justify use of the STL from a performance perspective. As a starting point, can anyone cite any benchmarks comparing vectors to plain old...
19
by: chris | last post by:
Hello, I've recently been trying to understand the various structures supplied by c++, and the one I find most confusing is deque. One quick question about this. It seems most implementations...
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
1
by: Dekker | last post by:
Hi I would like to transform the result of a csv-string (eg.: "name,age\nstring,int\nMac,23\nMax,24\nMike,78") into a map of vectors map<string, vector<???> >. The key of the map will be the...
13
by: JoeC | last post by:
I am completly lost. I would like to create a function that takes two vectors. These two vectors have objects with x and y coords, what I want to do find all the objects in the same x and y...
2
by: Ben Wheare | last post by:
Hiya, I'm fairly new to C++, and trying to figure out how to do the following: I have a class, strings, which has a private char array. To add to this array, I call the member function...
5
by: vasim98 | last post by:
I am surprised to see the output of the following C++ program using vectors. The program is so simple. An element is pushed in a vector "v" and the pointer to this element is obtained as "ptr_v"....
7
by: Markus Pitha | last post by:
Hello again, I have another question about the handling of multidimensional vectors. Actually, it's not difficult when the size is known at the beginning, but I still wasn't able to create...
5
by: Jim | last post by:
Hi, Just wondering which is better vector<record *r; r.push_back(new record(x,y)); or vector<recordr; r.push_back(record(x,y));
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.