Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Для новичков > Конструктор


Автор: docmai 3.10.2010, 21:07
Подскажите, как правильно оформить конструктор в этом коде ?
Код

struct Student
{
    public:
        Student(Student *s)
        {
            cout << "Enter the number of Z: \n";
            cin >> s->nZ;
            cout << "Enter name of student: \n";
            cin >> s->name;
        }
    protected:
        int nZ;
        char name[20];
};

int _tmain(int argc, _TCHAR* argv[])
{
    int nTemp;
    Student *s;
    cout << "Enter some key to end program: \n";
    cin >> nTemp;
    return 0;
}


Добавлено через 9 минут и 1 секунду
Спасибо всем заранее, разобрался

Автор: SVN74 3.10.2010, 21:23
Зачем усложнять жизнь...
Код

struct Student
{
    public:
        Student()
        {
            cout << "Enter the number of Z: \n";
            cin >> nZ;
            cout << "Enter name of student: \n";
            cin >> name;
        }
    protected:
        int nZ;
        char name[20];
};

int _tmain(int argc, _TCHAR* argv[])
{
    Student s;
    return 0;
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)