Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
// Header File

class CPrint
{ 
  void printf()
};

// Source File

void CPrint::printf()
{
  printf("Test"); // Here i want to access printf function of C library
  //But i gives the error no matching function for CPrint::printf(char[4])
}
Posted

1 solution

You must tell the compiler that the printf() function is not the one of your class but from global name space:
C++
void CPrint::printf()
{
  ::printf("Test");
}

In general it is a bad idea to use names of standard library functions as member function names. With C++ classes, it is common to let member function names begin with an uppercase letter:
C++
class CPrint
{
  void Printf();
};

// Source File

void CPrint::Printf()
{
  printf("Test");
}
 
Share this answer
 
Comments
LaxmikantYadav 25-Mar-13 8:53am    
Thanks Jochen, I know it is a bad idea to use names of standard library functions as member function names but just curious to know solution for the above case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900