C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - General Questions (Q.No. 24)
24.
Which of the following statements is correct about the program given below?
class Bix
{
public:
static void MyFunction();
};
int main()
{
void(*ptr)() = &Bix::MyFunction;
return 0;
}
Discussion:
19 comments Page 1 of 2.
Likitha said:
1 decade ago
Can someone explain?
Java said:
1 decade ago
What is linker error ? because on being compiled this program shows no error and no output.
Lenold said:
1 decade ago
Void data type should not return any value.
Bhanu said:
1 decade ago
Linker error is coming because we have redefine static function outside the class.
void Bix::Myfunction(); // Will solve linker problem.
void Bix::Myfunction(); // Will solve linker problem.
K SOWJANYA said:
1 decade ago
Can anybody explains clearly why it reports linking error?
Babbu said:
1 decade ago
What is linker error?
Vinay said:
1 decade ago
The linker error comes because the class is only declared and the definition is not there for the static member function. If we give a definition for member function then the linker error will be resolved by adding the following code.
void Bix::MyFunction()
{
std::cout << "I am a static function of Class Bix"
}
void Bix::MyFunction()
{
std::cout << "I am a static function of Class Bix"
}
Ankit.w. said:
1 decade ago
Function in main should be like :
void (Bix::*ptr)()= &Bix::Myfunction;
void (Bix::*ptr)()= &Bix::Myfunction;
Dipak Dhondge said:
1 decade ago
Compiler errors mean the compiler could not translate the source code you provided into object code. It usually means you have a syntactic or semantic error in your own program that you have to resolve before your program exhibits the behavior you're intending it to have.
Linker errors mean the linker could not build an executable program from the object code you provided. It usually means your program does not properly interface with its own dependencies or with the outside world (e.g. External libraries).
Linker errors mean the linker could not build an executable program from the object code you provided. It usually means your program does not properly interface with its own dependencies or with the outside world (e.g. External libraries).
Uday said:
1 decade ago
If you receive a linker error, it means that your code compiles fine, but that some function or library that is needed cannot be found. This occurs in what we call the linking stage and will prevent an executable from being generated. Many compilers do both the compiling and this linking stage.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers