主文件不会初始化对象

时间:2019-04-26 23:24:17

标签: c++

我正在尝试初始化头文件中定义的一些对象。无论出于什么原因,我的main.cpp甚至都拒绝查看初始化它们的代码。我认为这可能与我#include不同的头文件的方式有关,但我无法弄清楚到底是什么问题。

# include "node.h"
# include "data.h"
# include "list.h"
# include "menu.h"

# include <string>
# include <iostream>
# include <ctime>
# include <fstream>

using std::cout;
using std::endl;
using std::cin;
using std::ifstream;
using std::ofstream;


template<class t>
node<t> *newnode(t data)
{
    return new node<t>(data); // out here for scope
}

int main(void)
{
time_t time_ = time(0);   // get time now
struct tm * now = localtime(&time_);
cout << (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday << endl;

menu menu();

data data();

下面是菜单的功能定义。我已经尝试过更改对象名称(因此菜单对象未命名为menu),但显然没有帮助。所有头文件的顶部看起来都一样,唯一包含其他文件的文件是main。

#pragma once
# ifndef menu_
# define menu_


# include <iostream>
# include <fstream>

using std::cout;
using std::cin;
using std::ifstream;
using std::ofstream;


class menu
{
public:
    menu();
    void init();

private:
    int print();
    //void import();

    bool imported; // Tracker for if info is already loaded from masterList.txt

//ifstream classList;
//ofstream masterList;
};

menu::menu()
{
    imported = false;
    //classList.open("classList.txt");
    //masterList.open("masterList.txt");
}

void menu::init()
{
    int choice = this->print();

    //if (choice == 1)
        //this->import();
}



int menu::print()
{
    int choice;
    cout << "1. Import Course List\n2. Load Master List\n3. Store Master List\n4. Mark Absences\n5. Generate Report\n6. Exit";
    cin >> choice;
    return choice;
}
/*
void menu::import()
{

if (this->imported == false)
{
    string line;

    while (classList)
    {
        data temp; // may have to fix scope
        getline(classList, temp);

    }




}
}

*/


# endif menu_

0 个答案:

没有答案