C++ Static member function Question

Introduction

Write a program that defines a class with one static member function and one regular member function.

Make the functions public.

Define both member functions outside the class.

Access both functions in the main():

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 
#include <string> 

class MyClass 
{ 
public: 
    static void mystaticfunction(); 
    void myfunction(); 

}; 
void MyClass::mystaticfunction() 
{ 
    std::cout << "Hello World from a static member function." << '\n'; 
} 

void MyClass::myfunction() 
{ 
    std::cout << "Hello World from a regular member function." << '\n'; 
} 

int main() 
{ 
    MyClass::mystaticfunction(); 
    MyClass myobject; 
    myobject.myfunction(); 
} 



PreviousNext

Related