Some time ago, I had a segment of code like
vector<vector<i nt example;
f(example);
and inside f, I defined vector<int>'s and used push_back to get them
inside example. I got a segmentation fault which I resolved by doing
vector<vector<i nt example;
example.push_ba ck(vector<int>( ));
f(example);
I also remember that when debugging, I got the segmentation fault
right at the function call. I wonder why is it that I needed to do
this when the original code works if I had had a
vector<intexamp le
f(example)
and just pushed back integers inside f
I'm sorry because I don't have the actual code, this is a question
I'va had for a long time now and I simply don't have the code, but the
question is, can I pass vectors of vectors to a function without
initialising them and why if the answer is no?
Thanks
Daniel 2 3297 da************* @gmail.com wrote:
Some time ago, I had a segment of code like
vector<vector<i nt example;
f(example);
and inside f, I defined vector<int>'s and used push_back to get them
inside example. I got a segmentation fault which I resolved by doing
vector<vector<i nt example;
example.push_ba ck(vector<int>( ));
f(example);
There is no reason for this code to have undefined behaviour. The
usual UB cause is the attempted use of non-existent vector contents.
If you pushed an empty vector, that empty vector does not acquire
any 'int' elements until you push them too.
I also remember that when debugging, I got the segmentation fault
right at the function call.
Well, my memory is also known to fail me now and then. No need to
worry.
I wonder why is it that I needed to do
this when the original code works if I had had a
vector<intexamp le
f(example)
and just pushed back integers inside f
I'm sorry because I don't have the actual code, this is a question
I'va had for a long time now and I simply don't have the code, but the
question is, can I pass vectors of vectors to a function without
initialising them and why if the answer is no?
You _can_ pass vectors. They are not "without initialising". They
are *default-initialised*. They don't contain any elements, that's
true. So any attempted use of operator[] will most likely fail.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On 9 Feb 2007 04:59:24 -0800 in comp.lang.c++,
"da************ *@gmail.com" <da************ *@gmail.comwrot e,
>and inside f, I defined vector<int>'s and used push_back to get them inside example. I got a segmentation fault which I resolved by doing
vector<vector< int example; example.push_b ack(vector<int> ()); f(example);
Inside f() you probably do the equivalent of
example[0].push_back(42);
This fails if example[0] hasn't been created! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: kalinga1234 |
last post by:
there is a problem regarding passing array of characters to another
function(without using structures,pointer etc,).can anybody help me to
solve the problem.
|
by: Mike MacSween |
last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime
ago.
Then remembered that arguments are passed by reference, by default.
Does the fact that this slowed me down indicate:
a) That I don't know enough
b) Passing arguments by ref is bad
|
by: Pushkar Pradhan |
last post by:
I want a function to execute another function, which I pass to it,
sometimes it may be mm_6r6c_6r6c, mm_2r2c_2r2c, ... etc. thus this style.
double exec_basecase(void (*func)(double *a, double *b, double *c),
double *a, double *b, double *c, int numRowsA, int numColsA, int numColsB)
{
...../*other code*/
func(a, b, c);
.....
}
|
by: Mike D. |
last post by:
I have a problem with a dynamic library I am developing, but it is
really more of a pointer issue than anything else. Hopefully someone
here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another
function. For example:
int FunctionA ()
|
by: beetle |
last post by:
Hello,
I'm storing data in several different binary tree's.
The root node is located in a struct containing general data about the
tree.
struct lnode {
char *fname;
int nentry;
| |
by: jtagpgmr |
last post by:
I am currently using the gcc compiler on a cygwin platform, I am a
beginner when it comes to programming in C and want to know why anytime
I run the .exe with the following code I get a "segmentation fault
(core dumped)" error:
#include <stdio.h>
main()
{
|
by: Abubakar |
last post by:
Hi,
I compiled a simple code in c++/cli 2k5
public ref class Class1
{
public : void doit (char * c )
{
}
|
by: Kiran |
last post by:
Hi all,
What I am trying to do is to pass a pointer to the first element of
an array to a function, modify it in that function, and then print out
the values of the array (which has been modified by the function) in
main. However, I am getting a segmentation fault. Here is the code:
(Please note, the size is fixed in this code, but in my...
|
by: dorandoran |
last post by:
function openMyWindow()
{
var myID = document.getElementById('ctl00_maincontent_txtEmpID').value;
//var fname = document.getElementById('<%= lblFullName.ClientID %>').value;
//var lname = document.getElementById('ctl00_maincontent_txtlname').value;
var fname = document.getElementById('ctl00_maincontent_txtfname').value;
...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |