You need to create an instance of the class using the specified size of dynamic memory. I tried to register Stroka *stroka = new Stroka[10]; , but the message "expression must have class type" appears.
Error C2228 The expression to the left of ".vvod" must represent a class, structure, or union.
Also as I understand it, you need to implement a destructor.
~Stroka() // деструктор { delete[] str; }; Program code below:
#include "pch.h" #include <iostream> #include <iomanip> #include <stdlib.h> #include <conio.h> #include <stdio.h> #include <windows.h> #include <string.h> #include <malloc.h> using namespace std; class Stroka { char str[80]; public: Stroka(char*); //конструктор с параметром, ссылка на объект не фиксированного размера Stroka(const char*); //конструктор с параметром, ссылка на объект фиксированного размера Stroka() {}; //конструктор без параметров Stroka(const Stroka&); // Конструктор копирования void vvod(); void vyvod(); } ; Stroka::Stroka(char *string) { strcpy(str, string); } Stroka::Stroka(const Stroka& s) { strcpy(str, s.str); } void Stroka::vvod() { cout << "Введите текст:" << endl; cin >> str; } void Stroka::vyvod() { cout << "Вывод текста на экран:" << endl; cout << str << endl; } int main(int) { setlocale(0, ""); // установить русскую локацию Stroka *s1 = new Stroka[80]; //Stroka s1; s1.vvod(); s1.vyvod(); } ;