473,378 Members | 1,364 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,378 software developers and data experts.

non-pointer type warning when initializing vector with NULLs

Hi everyone,
I have the following piece of code:
vector<MyClass*> my_vector(10, NULL);

However this throws the following errors:
myfile.cc: warning: converting NULL to non-pointer type
stl_algobase.h: In function `class MyClass ** fill_n<MyClass **, int,
int>(MyClass **, int, const int &)':

While I understand the reasons for fill_n craping out (as it is not
able to get a pointer to the NULL value
passed by me), is there a way to initialize vector with NULLs? Or is it
safe to assume that vectors
will be initialized with NULLs? thanks!

Mar 2 '06 #1
4 5450

"Varun Kacholia" <ka******@gmail.com> schrieb im Newsbeitrag
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi everyone,
I have the following piece of code:
vector<MyClass*> my_vector(10, NULL);

However this throws the following errors:
myfile.cc: warning: converting NULL to non-pointer type
stl_algobase.h: In function `class MyClass ** fill_n<MyClass **, int,
int>(MyClass **, int, const int &)':

While I understand the reasons for fill_n craping out (as it is not
able to get a pointer to the NULL value
passed by me), is there a way to initialize vector with NULLs? Or is it
safe to assume that vectors
will be initialized with NULLs? thanks!


I would assume the NULL :S if you are not naive like me you can try a
vector<MyClass*> my_vector(10, (MyClass*)NULL);
Mar 2 '06 #2

Frank Schmidt wrote in message ...

"Varun Kacholia" <ka******@gmail.com> schrieb im Newsbeitrag
news:11**********************@j33g2000cwa.googleg roups.com...
Hi everyone,
I have the following piece of code:
vector<MyClass*> my_vector(10, NULL);

However this throws the following errors:
myfile.cc: warning: converting NULL to non-pointer type
stl_algobase.h: In function `class MyClass ** fill_n<MyClass **, int,
int>(MyClass **, int, const int &)':

While I understand the reasons for fill_n craping out (as it is not
able to get a pointer to the NULL value
passed by me), is there a way to initialize vector with NULLs? Or is it
safe to assume that vectors
will be initialized with NULLs? thanks!


I would assume the NULL :S if you are not naive like me you can try a
vector<MyClass*> my_vector(10, (MyClass*)NULL);


What do you think NULL is? Have you looked up it's definition in your
implementation?
[ from my MinGW ]
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void*)0)
#endif
#endif

Try:
std::vector<MyClass*> my_vector( 10, static_cast<MyClass*>(0) );
// This is a C++ group, why C style cast? <G>

or:
MyClass *tmp(0);
std::vector<MyClass*> my_vector( 10, tmp );

or simply:
std::vector<MyClass*> my_vector( 10 );
std::cout<<"Temp Test my_vector.at(0)= "<<my_vector.at(0)<<std::endl;
// output: Temp Test my_vector.at(0)= 0

I'll let one of the pros 'splain it. <G>
--
Bob R
POVrookie
Mar 2 '06 #3

"BobR" <Re***********@worldnet.att.net> schrieb im Newsbeitrag
news:F9****************@bgtnsc04-news.ops.worldnet.att.net...

Frank Schmidt wrote in message ...

"Varun Kacholia" <ka******@gmail.com> schrieb im Newsbeitrag
news:11**********************@j33g2000cwa.google groups.com...
Hi everyone,
I have the following piece of code:
vector<MyClass*> my_vector(10, NULL);

However this throws the following errors:
myfile.cc: warning: converting NULL to non-pointer type
stl_algobase.h: In function `class MyClass ** fill_n<MyClass **, int,
int>(MyClass **, int, const int &)':

While I understand the reasons for fill_n craping out (as it is not
able to get a pointer to the NULL value
passed by me), is there a way to initialize vector with NULLs? Or is it
safe to assume that vectors
will be initialized with NULLs? thanks!


I would assume the NULL :S if you are not naive like me you can try a
vector<MyClass*> my_vector(10, (MyClass*)NULL);


What do you think NULL is? Have you looked up it's definition in your
implementation?


No, but i saw that NULL does not match the vector type and that therefore
the compiler is choosing a different constructor.
Mar 2 '06 #4
Varun Kacholia wrote:
Hi everyone,
I have the following piece of code:
vector<MyClass*> my_vector(10, NULL);

However this throws the following errors:
myfile.cc: warning: converting NULL to non-pointer type
stl_algobase.h: In function `class MyClass ** fill_n<MyClass **, int,
int>(MyClass **, int, const int &)':

While I understand the reasons for fill_n craping out (as it is not
able to get a pointer to the NULL value
passed by me), is there a way to initialize vector with NULLs? Or is it
safe to assume that vectors
will be initialized with NULLs? thanks!

Why do you want to? I assume you will fill the vector, so why
initialise it? If you do, drop the NULL, the second parameter defaults
to T().

--
Ian Collins.
Mar 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
19
by: Christian Engström | last post by:
If you have a function that returns something by value, the gcc compiler (version 3.2.3 on Windows XP with MinGW) converts the returned value from the type you specify in the code, to the const...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
1
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
22
by: Steve - DND | last post by:
We're currently doing some tests to determine the performance of static vs non-static functions, and we're coming up with some odd(in our opinion) results. We used a very simple setup. One class...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
6
by: Fabian Wein | last post by:
Hi, is there a way to call a const function from non const function? I have a non-const List GetList(); and want my
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...

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.