From MSDN:
An __asm block can call only global C++ functions that are not overloaded. If you call an overloaded global C++ function or a C++ member function, the compiler issues an error.
You can ( if you dare ) however do a very very ( can't stress this enough: very ) dirty hack. In this SO post, you can see ways and concerns of - I died a little while writing the following - obtaining the address of your member function.
std::string mystring("Some characters");
std::string::const_reference(__thiscall std::string::*atFunc)(std::string::size_type) const = &std::string::at;
unsigned int atAddress = PtrToUlong((void*&)atFunc);
char output = 0;
__asm
{
mov eax, atAddress
push 5
lea ecx, [mystring]
call eax
mov al, [eax]
mov [output], al
}
std::cout << "Output is: " << output << std::endl;
If I were a supervisor, and one of my programmer minions would do this in production code, I would slap him/her with a big stinky fish. Use on your own risk.
The far more sane solution is to simply ditch any std::string
usage from the __asm
block:
std::string mystring("Some characters");
const char * cstr = mystring.c_str();
char output = 0;
__asm
{
mov eax, [cstr]
mov al, [eax+3]
mov [output],al
}
std::cout << "Output is: " << output << std::endl;