C++ what to code if i put a class after main() function

前端 未结 5 1000
滥情空心
滥情空心 2020-12-30 17:26

I\'m watching some video tutorials on C++ and i know you must define a function / class before it is used or called. But I like having my main() function at the top, and eve

5条回答
  •  既然无缘
    2020-12-30 17:51

    One scenario where the class definition after the main() function makes sense:

    #include 
    using namespace std;
    
    void f();
    
    int main()
    {
        f();
        return 0;
    }
    
    class ClassOne
    {
        public:
            void coolSaying()
            {
                cout << "Cool stuff yo!" << endl;
            }
    };
    
    void f()
    {
        ClassOne one;
        one.coolSaying();
    }
    

提交回复
热议问题