首页 > 解决方案 > 未找到标识符 - Visual Studio 2019 中的错误 C3861

问题描述

我的代码有问题。不幸的是,在编译时我总是遇到这些错误。这可能是由什么引起的以及如何解决?

错误 C3861:“打印”:未找到标识符

我的代码:

主文件

#include "pojazdy.h"
#include <iostream>

using namespace std;

int main()
{
    Pojazdy** poj;
    int size{ 0 }, index{ 0 };
    Petla(poj, size);

    print(poj, size);

    wyrejestruj(poj,size,0);
    print(poj, size);
    wyrejestruj(poj,size);

    return 0;
}

pojazdy.h

#ifndef pojazdy_h
#define pojazdy_h

#include <iostream>
#include <cstdlib>

using namespace std;

class Pojazdy
{
public:
    string typ;
    string marka;
    string model;
    string z_dod;
    int ilosc;
    int cena;

    void dodaj();
    void d_pojazd(Pojazdy**& pojazdy, int& size);
    void wyrejestruj(Pojazdy**& pojazdy, int& size, int index);
    void print(Pojazdy** pojazdy, int size);
    void Petla(Pojazdy**& p, int& size);

    //void wyswietl();
    int get_ilosc() { return ilosc; }
    string get_typ() { return typ; }
    string get_marka() { return marka; }
    string get_model() { return model; }
    int get_cena() { return cena; }
    void set_ilosc(int x);
};

#endif

pojazdy.cpp

#include "pojazdy.h"

#include <iostream>

using namespace std;

void Pojazdy::set_ilosc(int x) { ilosc = x; }

void Pojazdy::dodaj()
{
    cout << "DODAWANIE POJAZDU..." << endl;
    cout << "Podaj typ pojazdu:";
    cin >> typ;

    cout << "Podaj marke pojazdu: ";
    cin >> marka;

    cout << "Podaj model pojazdu: ";
    cin >> model;

    cout << "Dodaj cene pojazdu: ";
    cin >> cena;
}

void Petla(Pojazdy**& p, int& size) {
    char z_dod;// = 'N';
    do {
        d_pojazd(p, size); //odpowiada za dodawnie
        p[size - 1]->dodaj();
        cout << "Czy chcesz zakonczyc dodawanie? Jesli tak, wcisnij Y/N: ";
        cin >> z_dod;

    } while (z_dod == 'N' || z_dod == 'n');//while (p[size]->z_dod == "N" ||p[size]->z_dod == "n");
}

void print(Pojazdy** pojazdy, int size) {
    std::cout << "====================================" << std::endl;
    for (int i{ 0 }; i < size; i++)
        std::cout << "Typ: " << pojazdy[i]->get_typ() << " Marka: " << pojazdy[i]->get_marka() << " Model: " << pojazdy[i]->get_model() << " Cena: " << pojazdy[i]->get_model() << std::endl;
}

void wyrejestruj(Pojazdy**& pojazdy, int& size) {
    for (size_t i{ 0 }; i < size; i++)
        delete pojazdy[i];
    delete[] pojazdy;
    size = 0;
    pojazdy = NULL;
}

void wyrejestruj(Pojazdy**& pojazdy, int& size, int index) {
    if (index < size) {
        Pojazdy** temp = new Pojazdy * [size - 1];
        short int j{ -1 };
        for (size_t i{ 0 }; i < size; i++) {
            if (i != index) {
                j++;
                temp[j] = pojazdy[i];
            }
        }
        delete[] pojazdy;
        --size;
        pojazdy = temp;
    }
    else
        std::cout << "Pamiec zwolniona!" << std::endl;
}

void d_pojazd(Pojazdy**& pojazdy, int& size) {
    Pojazdy** temp = new Pojazdy * [size + 1];
    if (size == 0)
        temp[size] = new Pojazdy;
    else {
        for (int i{ 0 }; i < size; i++)
            temp[i] = pojazdy[i];
        delete[] pojazdy;

        temp[size] = new Pojazdy;
    }
    ++size;
    pojazdy = temp;
}

我用过#ifndef,和#define,但它们都不起作用。我将非常感谢每一个代码,我已经厌倦了第二个小时。并原谅它们的非英语变量和函数名称 - 这是大学代码,所以我觉得没有必要。#endif#pragma once

标签: c++visibilityfunction-declaration

解决方案


将下面的函数移到类声明之外。

void wyrejestruj(Pojazdy**& pojazdy, int& size, int index);
void print(Pojazdy** pojazdy, int size);
void Petla(Pojazdy**& p, int& size);

或者使它们成为静态并调用 like Pojazdy::print(poj, size);


推荐阅读