Click here to Skip to main content
Rate this: bad
good
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 3: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 at 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
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2014
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