c++ - 未找到标识符 - 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
解决方案
将下面的函数移到类声明之外。
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);
。
推荐阅读
- c++ - 如何使用 *pointer 从函数中获取第二个值?
- python - 我试图在同一个项目中为第二个应用程序使用基于类的视图,但是,更改没有通过?
- path - env.var 时在 Windows 10 的运行功能中启动了错误的文件。路径包含多个名称相似的文件
- python - Apache Airflow:如何动态触发多个 DAG?
- flutter - 在 Flutter 中添加 flutter_facebook_login 时出现 MissingPluginException
- typescript - Google Chrome 扩展程序 - 弹出窗口未显示且无法检查背景页面
- javascript - 使用 Router 的组件未显示在 Button 单击事件上
- git - 如何从 gitolite 获取远程存储库列表?
- scala - 在播放框架中的对象内调用 WSClient 的 Scala 类方法
- python - Scikit-learn 扩展的自定义 one-hot 编码矩阵 - 不是从数据集构建的