Using a class function in int main()

前端 未结 6 969
悲哀的现实
悲哀的现实 2020-12-20 09:49

I am having problems calling my functions from my main program.
These functions HAVE to be in my class.
How do I access them from my int main()?

#inc         


        
6条回答
  •  心在旅途
    2020-12-20 10:27

    You need to create an instance of the class (an object) in order to call his member functions.

    In this particular code the member functions has no reason to be instance and could be static:

    class foo{
        public:
    
        static void bar(int val)
        {
        //do something
        }
        };
    
    int main()
    {
       foo::bar(10);
    }
    

提交回复
热议问题