Is this really returning a local addess?
I have some code which creates a synchronised queue which I use in a data gathering class to report it's data. The method which creates queues is kicking up a warning:
Queue^% DataGatherer::AddOutputQueue()
{
Queue^ outputQueue = Queue::Synchronized(gcnew Queue);
开发者_如何学编程 AddOutputQueue(outputQueue);
return outputQueue;
}
1>.\DataGatherer.cpp(21) : warning C4172: returning address of local variable or temporary
Is this a warning I should be worried about or am I safe in this case and it's just the compiler getting confused about Queue::Synchronized
returning a Queue^
? The code appears to run fine, but warnings make me nervous ;-)
Queue^%
indicates a handle being passed by reference. However, the handle inside the func is a local variable which can't be passed by reference since it's potentially destroyed when the func finishes. Remove the %
from the return type and you are fine.
Edit: It doesn't mean anything your code seems to work. It can stop doing so any minute.
精彩评论