Visual studio ошибка c3861

description title ms.date f1_keywords helpviewer_keywords ms.assetid

Learn more about: Compiler Error C3861

Compiler Error C3861

06/29/2022

C3861

C3861

0a1eee30-b3db-41b1-b1e5-35949c3924d7

Compiler Error C3861

identifier‘: identifier not found

The compiler was unable to resolve a reference to an identifier, even using argument-dependent lookup.

Remarks

To fix this error, compare use of identifier to the identifier declaration for case and spelling. Verify that scope resolution operators and namespace using directives are used correctly. If the identifier is declared in a header file, verify that the header is included before the identifier is referenced. If the identifier is meant to be externally visible, make sure that it’s declared in any source file that uses it. Also check that the identifier declaration or definition isn’t excluded by conditional compilation directives.

Changes to remove obsolete functions from the C Runtime Library in Visual Studio 2015 can cause C3861. To resolve this error, remove references to these functions or replace them with their secure alternatives, if any. For more information, see Obsolete functions.

If error C3861 appears after project migration from older versions of the compiler, you may have issues related to supported Windows versions. Visual C++ no longer supports targeting Windows 95, Windows 98, Windows ME, Windows NT or Windows 2000. If your WINVER or _WIN32_WINNT macros are assigned to one of these versions of Windows, you must modify the macros. For more information, see Modifying WINVER and _WIN32_WINNT.

Examples

Undefined identifier

The following sample generates C3861 because the identifier isn’t defined.

// C3861.cpp
void f2(){}
int main() {
   f();    // C3861
   f2();   // OK
}

Identifier not in scope

The following sample generates C3861, because an identifier is only visible in the file scope of its definition, unless it’s declared in other source files that use it.

Source file C3861_a1.cpp:

// C3861_a1.cpp
// Compile with: cl /EHsc /W4 C3861_a1.cpp C3861_a2.cpp
#include <iostream>
// Uncomment the following line to fix:
// int f();  // declaration makes external function visible
int main() {
   std::cout << f() << std::endl;    // C3861
}

Source file C3861_a2.cpp:

// C3861_a2.cpp
int f() {  // declared and defined here
   return 42;
}

Namespace qualification required

Exception classes in the C++ Standard Library require the std namespace.

// C3861_b.cpp
// compile with: /EHsc
#include <iostream>
int main() {
   try {
      throw exception("Exception");   // C3861
      // try the following line instead
      // throw std::exception("Exception");
   }
   catch (...) {
      std::cout << "caught an exception" << std::endl;
   }
}

Obsolete function called

Obsolete functions have been removed from the CRT library.

// C3861_c.cpp
#include <stdio.h>
int main() {
   char line[21]; // room for 20 chars + ''
   gets( line );  // C3861
   // Use gets_s instead.
   printf( "The line entered was: %sn", line );
}

ADL and friend functions

The following sample generates C3767 because the compiler can’t use argument dependent lookup for FriendFunc:

namespace N {
   class C {
      friend void FriendFunc() {}
      friend void AnotherFriendFunc(C* c) {}
   };
}

int main() {
   using namespace N;
   FriendFunc();   // C3861 error
   C* pC = new C();
   AnotherFriendFunc(pC);   // found via argument-dependent lookup
}

To fix the error, declare the friend in class scope and define it in namespace scope:

class MyClass {
   int m_private;
   friend void func();
};

void func() {
   MyClass s;
   s.m_private = 0;
}

int main() {
   func();
}

I have a problem with my code. Unfortunately, when compiling I get these errors all the time. What can this be caused by and how to fix it?

error C3861: ‘print’: identifier not found

My code:

main.cpp

#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;
}

I used #ifndef, #define, #endif and #pragma once, but none of them work. I will be really grateful for every code, I am already tired of this second hour. And forgive the non-English variables and function names for them — it’s university code, so I didn’t feel the need.

  • Remove From My Forums
  • Question

  • My C++ code compiles fine with VS 2013 but when I have compiled with VS 2015 I get this error:

    C:Program Files (x86)Microsoft Visual Studio 14.0VCatlmfcincludeatlwinverapi.h(710): error C3861: 'LCMapStringEx': identifier not found
    

    I don’t use LCMapString anywhere in my code, so I don’t know where this come from? Can you help me in resolving this error?

    • Moved by

      Wednesday, January 11, 2017 7:21 AM

Answers

    • Marked as answer by
      smhaneef
      Wednesday, January 11, 2017 2:40 PM

You need to move calc_grade above grade so that it knows it exists. Or declare it above like this.

double calc_grade(double midterm, double final, std::vector<double>& homework);

Your grade method is marked const, so it may not change your class. But you are calling calc_grade which does not take a const vector therefor it could change the class member you are handing it. You can make it take a const vector to solve this. I would make that method const as well to keep things consistent.

One possible fix:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//////////////////////////////////////////////////////////
//////////////////////////CORE CLASS//////////////////////
//////////////////////////////////////////////////////////
class Core {
public:
    Core() : midterm(0), final(0) { }
    Core(std::istream& is) { read(is); }

    std::string name() const;

    virtual std::istream& read(std::istream&);
    virtual double grade() const;
protected:
    std::istream& read_common(std::istream&);
    std::istream& read_hw(std::istream&, std::vector<double>&);
    double midterm, final;
    std::vector<double> homework;
private:    
    std::string n;  
};

std::string Core::name() const { return n; }


double calc_grade(double midterm, double final, const std::vector<double>& homework)
{
    double result = 0.0;
    for (std::vector<double>::const_iterator i = homework.begin(); i != homework.end(); ++i)
        result += *i;

    return midterm*0.4 + final*0.4 + (result / homework.size())*0.2;
}


double Core::grade() const
{
    return calc_grade(midterm, final, homework);
}

std::istream& Core::read_common(std::istream& in)
{
    in >> n >> midterm >> final;
    return in;
}

std::istream& Core::read(std::istream& in)
{
    read_common(in);
    read_hw(in, homework);
    return in;
}

std::istream& Core::read_hw(std::istream& in, std::vector<double>& homework)
{
    double input;
    while (in >> input)
        homework.push_back(input);

    return in;
}

//////////////////////////////////////////////////////////
//////////////////////////GRAD CLASS//////////////////////
//////////////////////////////////////////////////////////
class Grad : public Core {
public:
    Grad() : thesis(0) { }
    Grad(std::istream& is) { read(is); }

    double grade() const;
    std::istream& read(std::istream&);
private:
    double thesis;
};

std::istream& Grad::read(std::istream& in)
{
    read_common(in);
    in >> thesis;
    read_hw(in, homework);
    return in;
}

double Grad::grade() const
{
    return std::min(Core::grade(), thesis);
}

//////////////////////////////////////////////////////////
//////////////////////MISCELLANEOUS///////////////////////
//////////////////////////////////////////////////////////
bool compare_grades(const Core& c1, const Core& c2)
{
    return c1.grade() < c2.grade();
}

bool compare_Core_ptrs(const Core* cp1, const Core* cp2)
{
    return compare_grades(*cp1, *cp2);
}

using namespace std;

int main()
{
    vector<Core*> students;
    Core* record;
    char ch;
    string::size_type maxlen = 0;

    while (cin >> ch)
    {
        if (ch == 'U')
            record = new Core;
        else
            record = new Grad;
        record->read(cin);
        maxlen = max(maxlen, record->name().size());
        students.push_back(record);
    }

    sort(students.begin(), students.end(), compare_Core_ptrs);

    for (vector<Core*>::size_type i = 0; i != students.size(); ++i)
    {
        cout << students[i]->name() << string(maxlen + 1 - students[i]->name().size(), ' ');
        try
        {
            double final_grade = students[i]->grade();
            streamsize prec = cout.precision();
            cout << setprecision(3) << final_grade << setprecision(prec) << endl;
        }
        catch (domain_error e)
        {
            cout << e.what() << endl;
        }
        delete students[i];
    }
    return 0;
}

01.04.2016, 22:52. Показов 42231. Ответов 2


Студворк — интернет-сервис помощи студентам

Не суть важен текст программы, как то, что у меня не получается подключить функции.
Выдает ошибку:
С3861 «название функции»: идентификатор не найден

Подскажите, пожалуйста, что делать.
Вот что я нашел:
]identifier: идентификатор не найден
Компилятору не удалось разрешить ссылку на идентификатор даже при поиске с зависимостью от аргументов.
Чтобы устранить эту ошибку, проверьте написание и регистр объявления идентификатора. Убедитесь, что операторы разрешения области действия и директивы using пространства имен используются правильно. Если идентификатор объявляется в файле заголовка, убедитесь, что заголовок включен до ссылки на него. Кроме того, убедитесь, что идентификатор не исключен с помощью директив условной компиляции.

Но, честно говоря, не особо понял что надобно делать.
Может, я что-то не подключил?

А вообще, в начале всего этого просто выделяется память для динамического двумерного массива.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
 
void main()
{
    setlocale(LC_ALL, "Russian");
    int n, p;
    double **a = NULL;
    double **b = NULL;
    double **c = NULL;
    double **a1 = NULL;
    double **b1 = NULL;
    cout << "Введите размерность массива (число n): ";
    cin >> n;
    NewMemory(a, n);
    NewMemory(b, n);
    NewMemory(c, n);
    NewMemory(a1, n);
    NewMemory(b1, n);
 
    do
        {
            system("cls");
            cout << "1. Создание матрицы a " << endl;
            cout << "2. Создание матрицы b " << endl;
            cout << "3. Нахождение m-нормы матрицы a" << endl;
            cout << "4. Умножение матрицы B на число (b1= b*am)" << endl;
            cout << "5. Вычитание матриц(a1=a-b1)" << endl;
            cout << "6. Обращение матрицы( с=a1^(-1)" << endl;
            cout << "7. Вывод всех матриц(a, a1, b, b1, c)" << endl;
            cout << "8. Конец работы" << endl << endl;
            cout << "Укажите пункт меню: ";
            cin >> p;
            switch (p) 
            {
            case 1: AarrayCreator(a, n);
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
                break;
            case 6:
                break;
            case 7:
                break;
            case 8:
                DeleteArray(a, n);
                DeleteArray(b, n);
                DeleteArray(c, n);
                DeleteArray(a1, n);
                DeleteArray(b1, n);
                return;
            }
            _getch();
        } while (true);
    system("Pause");
}
 
 
void NewMemory(double **&h, int n)
{
    h = new double* [n];
    for (int i = 0; i < 2; i++)
        h[i] = new double[n];
}
 
void DeleteArray(double **&h, int n)
{
    for (int i = 0; i < n; i++)
        delete[] h[i];
}
 
double AarrayCreator(double **h, int n) {
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            h[i][j] = (sin(i + j))*sin(i + j);
}

P.S. я не знаю насколько правильный весь код. Сразу извиняюсь за корявость
P.S.S Ошибку он мне выдает на каждое объявление функции. Всех функций



0



Возможно, вам также будет интересно:

  • Visual studio ошибка 1168
  • Visual studio окно ошибок как открыть
  • Visual studio не подчеркивает ошибки
  • Visual studio как отключить ошибку
  • Visual studio как включить отображение ошибок

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии