Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return NULL in function that should return a vector

Tags:

c++

null

vector

I have a function with the following header:

std::vector<NxU32> MySewer::createCuttingArray(MyCloth** cloth, NxU32 startPoint, NxU32 endPoint)

The function is supposed to return a vector containing some integer values. But there is one problem: If the line is not correctly created (there is a way in which this can happen), I want to do something like what I did in Java and C#, to return a NULL. But from what I see, in C++, NULL is defined as an integer value. How can I return a valid NULL for a vector?

like image 955
user2399378 Avatar asked Dec 01 '22 19:12

user2399378


1 Answers

The "correct" way to deal with this really depends on what the code receiving the vector actually does. Is it cause for an error, or simply "we ignore this"?

If it's an error, use throw some_exception_goes_here;, because that is much easier than going down the line with a NULL value.

If you want to just ignore it, return an empty vector and then make sure the code below isn't going to have problems with an empty vector.

like image 117
Mats Petersson Avatar answered Dec 13 '22 08:12

Mats Petersson