Click here to Skip to main content
12,395,183 members (60,544 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
// 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 25-Mar-13 2:07am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You must tell the compiler that the printf() function is not the one of your class but from global name space:
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:
class CPrint
{
  void Printf();
};
 
// Source File

void CPrint::Printf()
{
  printf("Test");
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100