bash search function

I want to have a function with a similar interface:

search *.cpp asdf

that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this:

function search { find . -name "$1" | xargs grep -li $2; }

But it doesn't work all the time. For example, if i run it in dir1:

dir1
\dir2
\\file2.cpp
\file1.cpp

it only greps file1.cpp without going down to file2.cpp. I figured out it happens because of globbing *.cpp to the list of files in dir1, but i have no idea, how to avoid it in function without turning globbing off. Quotes do not help either. Any ideas?

Search Current Directory

egrep asdf *.cpp

Search all directories under current including current:

egrep -R asdf *.cpp

Did you try:

search "*.cpp" asdf

Thanks for a shorter solution, but it still doesn't go to dir2.
I think *.cpp is extanding to file1.cpp and then we have

egrep -R asdf file1.cpp

Strange, i was sure i tried it before and it didn't help. However it works now :confused: Thanks