Меню

Error c2061 синтаксическая ошибка идентификатор listbox

description title ms.date f1_keywords helpviewer_keywords ms.assetid

Learn more about: Compiler Error C2061

Compiler Error C2061

11/04/2016

C2061

C2061

b0e61c0c-a205-4820-b9aa-301d6c6fe6eb

Compiler Error C2061

syntax error : identifier ‘identifier’

The compiler found an identifier where it wasn’t expected. Make sure that identifier is declared before you use it.

An initializer may be enclosed by parentheses. To avoid this problem, enclose the declarator in parentheses or make it a typedef.

This error could also be caused when the compiler detects an expression as a class template argument; use typename to tell the compiler it is a type.

The following sample generates C2061:

// C2061.cpp
// compile with: /c
template < A a >   // C2061
// try the following line instead
// template < typename b >
class c{};

C2061 can occur if you pass an instance name to typeid:

// C2061b.cpp
// compile with: /clr
ref struct G {
   int i;
};

int main() {
   G ^ pG = gcnew G;
   System::Type ^ pType = typeid<pG>;   // C2061
   System::Type ^ pType2 = typeid<G>;   // OK
}


Recommended Answers

Making your FIGURE_TYPE struct from your Figure class public can solve your problem. Presumably your FIGURE_TYPE is in the defauls private block of your class, which means you can’t access it directly. Making it public allows other classes to use that struct, even if it’s declared in …

Jump to Post

This might be basic, but have you included UI.h in the current file?

Jump to Post

All 5 Replies

Member Avatar

10 Years Ago

Making your FIGURE_TYPE struct from your Figure class public can solve your problem. Presumably your FIGURE_TYPE is in the defauls private block of your class, which means you can’t access it directly. Making it public allows other classes to use that struct, even if it’s declared in the Figure class.
Here’s a small example:

#include <iostream>
using namespace std;
#define NR 5

class SDL_Rect{};
class A{
public:
    struct FIGURE_TYPE {
        SDL_Rect crop;
        int x;
        int y;
    };
};

class B{
public:
    void printFig(A::FIGURE_TYPE figure_index[NR]){
        for (int i=0;i<NR;i++){
            cout<<"X: "<<figure_index[i].x<<" Y: "<<figure_index[i].y<<endl;
        }
    }
};

int main(){
    A::FIGURE_TYPE figs[NR];
    for (int i=0;i<NR;i++){
        figs[i].x=i+10;
        figs[i].y=i+20;
    }
    B().printFig(figs);
    return 0;
}

Member Avatar

10 Years Ago

It is public. Any other ideas?

Thank you for taking an interest, by the way.

Member Avatar

10 Years Ago

This might be basic, but have you included UI.h in the current file?

Member Avatar

10 Years Ago

It turns out I had a circular dependency with my headers. Thank you for helping though!

Member Avatar


Reply to this topic

Be a part of the DaniWeb community

We’re a friendly, industry-focused community of developers, IT pros, digital marketers,
and technology enthusiasts meeting, networking, learning, and sharing knowledge.

What’s wrong with this line of code?

bar foo(vector ftw);

It produces

error C2061: syntax error: identifier 'vector'

bdonlan's user avatar

bdonlan

220k29 gold badges264 silver badges321 bronze badges

asked Jun 11, 2010 at 22:04

Nick Heiner's user avatar

Nick HeinerNick Heiner

117k183 gold badges472 silver badges696 bronze badges

try std::vector instead. Also, make sure you

#include <vector>

answered Jun 11, 2010 at 22:06

Adrian Grigore's user avatar

Adrian GrigoreAdrian Grigore

32.8k36 gold badges130 silver badges209 bronze badges

Probably you forgot to include vector and/or import std::vector into the namespace.

Make sure you have:

#include <vector>

Then add:

using std::vector;

or just use:

bar foo(std::vector<odp> ftw);

answered Jun 11, 2010 at 22:06

Matthew Flaschen's user avatar

Matthew FlaschenMatthew Flaschen

274k50 gold badges513 silver badges537 bronze badges

1

Do you have:

#include <vector>

and

using namespace std; in your code?

<vector> defines the std::vector class, so you need to include it some where in your file.

since you’re using vector, you need to instruct the compiler that you’re going to import the whole std namespace (arguably this is not something you want to do), via using namespace std;

Otherwise vector should be defined as std::vector<myclass>

answered Jun 11, 2010 at 22:06

Alan's user avatar

try std::vector<odp> or using std;

answered Jun 11, 2010 at 22:06

TreDubZedd's user avatar

TreDubZeddTreDubZedd

2,5311 gold badge15 silver badges19 bronze badges

On its own, that snippet of code has no definition of bar, vector or odp. As to why you’re not getting an error about the definition of bar, I can only assume that you’ve taken it out of context.

I assume that it is supposed to define foo as a function, that vector names a template and that it is supposed to define a parameter called ftw but in a declaration anything that is not actually being defined needs to have been declared previously so that the compiler knows what all the other identifiers mean.

For example, if you define new types as follows you get a snippet that will compile:

struct bar {};
struct odp {};
template<class T> struct vector {};

bar foo(vector<odp> ftw);

answered Jun 11, 2010 at 22:07

CB Bailey's user avatar

CB BaileyCB Bailey

731k101 gold badges625 silver badges651 bronze badges

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#pragma once
#include "MyForm.h"
#include <Windows.h>
#include <string>
#include <math.h>
#include <tchar.h>
#include <Windows.h>
#include "../../../../../../Program Files (x86)/EASendMail/Include/tlh/easendmailobj.tlh"
#include "Test.h"
using namespace EASendMailObjLib;
using std::string;
namespace Final {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
 
    /// <summary>
    /// Сводка для MyForm
    /// </summary>
    public ref class MyForm : public System::Windows::Forms::Form
    {
    public:
        MyForm(void)
        {
            InitializeComponent();
            //
            //TODO: добавьте код конструктора
            //
        }
 
    protected:
        /// <summary>
        /// Освободить все используемые ресурсы.
        /// </summary>
        ~MyForm()
        {
            if (components)
            {
                delete components;
            }
        }
 
    private: System::Windows::Forms::TextBox^ textBox1;
    private: System::Windows::Forms::Button^ button1;
 
    private: System::Windows::Forms::Label^ label1;
 
    private: System::Windows::Forms::PictureBox^ pictureBox2;
    private: System::Windows::Forms::PictureBox^ pictureBox1;
 
 
 
    protected:
 
    protected:
 
    private:
        /// <summary>
        /// Обязательная переменная конструктора.
        /// </summary>
        System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// Требуемый метод для поддержки конструктора — не изменяйте 
        /// содержимое этого метода с помощью редактора кода.
        /// </summary>
        void InitializeComponent(void)
        {
            System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox2))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
            this->SuspendLayout();
            // 
            // textBox1
            // 
            this->textBox1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(64)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
                static_cast<System::Int32>(static_cast<System::Byte>(64)));
            this->textBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
            this->textBox1->Font = (gcnew System::Drawing::Font(L"Chiller", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->textBox1->ForeColor = System::Drawing::Color::DarkRed;
            this->textBox1->Location = System::Drawing::Point(111, 104);
            this->textBox1->Multiline = true;
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(238, 64);
            this->textBox1->TabIndex = 1;
            this->textBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::textBox1_TextChanged);
            // 
            // button1
            // 
            this->button1->Font = (gcnew System::Drawing::Font(L"Agency FB", 15.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->button1->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
            this->button1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button1.Image")));
            this->button1->Location = System::Drawing::Point(158, 200);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(148, 35);
            this->button1->TabIndex = 2;
            this->button1->Text = L"Examine me, creator!";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->BackColor = System::Drawing::Color::Black;
            this->label1->Font = (gcnew System::Drawing::Font(L"Agency FB", 32.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->label1->ForeColor = System::Drawing::Color::Maroon;
            this->label1->Location = System::Drawing::Point(21, 25);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(422, 52);
            this->label1->TabIndex = 3;
            this->label1->Text = L"What is wrong with my data";
            this->label1->Click += gcnew System::EventHandler(this, &MyForm::label1_Click_1);
            // 
            // pictureBox2
            // 
            this->pictureBox2->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
            this->pictureBox2->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox2.Image")));
            this->pictureBox2->Location = System::Drawing::Point(192, 264);
            this->pictureBox2->Name = L"pictureBox2";
            this->pictureBox2->Size = System::Drawing::Size(82, 44);
            this->pictureBox2->TabIndex = 4;
            this->pictureBox2->TabStop = false;
            // 
            // pictureBox1
            // 
            this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.Image")));
            this->pictureBox1->Location = System::Drawing::Point(-83, -23);
            this->pictureBox1->Name = L"pictureBox1";
            this->pictureBox1->Size = System::Drawing::Size(564, 358);
            this->pictureBox1->TabIndex = 0;
            this->pictureBox1->TabStop = false;
            this->pictureBox1->Click += gcnew System::EventHandler(this, &MyForm::pictureBox1_Click);
            // 
            // MyForm
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->BackColor = System::Drawing::SystemColors::ControlLightLight;
            this->ClientSize = System::Drawing::Size(465, 320);
            this->Controls->Add(this->pictureBox2);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->pictureBox1);
            this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
            this->MaximizeBox = false;
            this->Name = L"MyForm";
            this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
            this->Text = L"Final";
            this->TopMost = true;
            this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox2))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
            this->ResumeLayout(false);
            this->PerformLayout();
 
        }
#pragma endregion
    private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
    }
    private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e)
    {
        
    }
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) 
    {
        int n;
        char k;
        string s;
        if (textBox1->Text->Length == 0)
        {
            MessageBox::Show("Don't push it without reason");
        }
        else
        {
 
 
            n = textBox1->Text->Length;
 
            for (int i = 0; i < n; i++)
            {
                k = tolower(textBox1->Text[i]);
                s = s + k;
            }
 
        }
        if (s == "your data stinks")
        {
            Test^ f2 = gcnew Test();
            f2->Show();
        }
        else
        {
            MessageBox::Show("No.");
        }
    }
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label1_Click_1(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void pictureBox2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
  • Remove From My Forums
  • Question

  • I just learned C++. All the book examples worked well on my Visual C++ 2005 Express Edition.

    Now I correctly built a large C project that I got from somebody else. I wanted to add a simple C++ file to it defining only one class:

    class HK

    {

    public:

    HK() {} // Constructor

    ~HK() {} // Destructor

    static int Ones();

    };

     int HK::Ones()

    {

    return 1;

    }

    This class compiled correctly when done separately. But as soon as I wanted to build it togeter with the correct C code, I got the C++ class definition error C2061.

    Now, I tried to find the reason, seriously. I have printed 200 pages of Microsoft documentation so far, but have not discovered what this is?

    Help!  What could be the reason and how can I integrate this C++ code with the older C code?

    Greetings

    Heinz

  • Remove From My Forums
  • Question

  • Hi. I got error message when I try to build my project

    «d:Documents and SettingsPhoenixМои документыMy_appautonapominalkamain.cpp(164): error C2061: syntax error : identifier ‘form1′»

    Code sample:
    //—————————

    Form * form1 = new error;

    //some code


    form1->Controls->Add(listbox);// error shows on this string

    form1->Show();
    //——————————

    So, I have declaration but Visual C++ thinks that form1 is undeclarated. How can i resolve the problem?

    I use Visual Studio .NET 2003

Answers

  • Could you post a complete small sample code that can reproduce the issue?

    Edit:
    Marking the post as correct answer. Please unmark the post once you post a sample.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • Remove From My Forums
  • Question

  • Hi. I got error message when I try to build my project

    «d:Documents and SettingsPhoenixМои документыMy_appautonapominalkamain.cpp(164): error C2061: syntax error : identifier ‘form1′»

    Code sample:
    //—————————

    Form * form1 = new error;

    //some code


    form1->Controls->Add(listbox);// error shows on this string

    form1->Show();
    //——————————

    So, I have declaration but Visual C++ thinks that form1 is undeclarated. How can i resolve the problem?

    I use Visual Studio .NET 2003

Answers

  • Could you post a complete small sample code that can reproduce the issue?

    Edit:
    Marking the post as correct answer. Please unmark the post once you post a sample.

    Thanks,
      Ayman Shoukry
      VC++ Team

Синтаксическая ошибка: идентификатор «Player». Файл mob.h ст 40
Гуглить пробовал. Ответ так и не нашел

player.h:

#pragma once
#include "Weapon.h"
#include "Mob.h"

class Player
{
public:
	int health, armor, exp, mana;
	int currentHealth, currentArmor, currentMana, toNextLvlExp, balance;
	int missChanceBody, missChanceHead, missChanceLegs;

	Weapon sword;
	Weapon magicStick;

	Player(int _health, int _armor, const Weapon& _sword, const Weapon& _magicStick);
	int takePhysicalDamage(Mob& m);
};

mob.h:

#pragma once
#include <string>
#include "Player.h"

using namespace std;

class Mob
{
public:
	enum mobType {
		PHYSIC,
		MAGIC
	};

	enum attackDir {
		HEAD,
		BODY,
		LEGS
	};

	int health, armor, magicResistance, shockResistance;
	int currentHealth, damage, spreadDamage;
	string name;
	mobType attackType;

	

	/**
	 * Конструктор класса Mob.
	 * Принимает 3 аргумента
	 * _health - здоровье моба
	 * _magicResistance - защита от магического урона
	 * _shockResistance - защита от физического урона
	 * _damage - урон
	 * _spreadDamage - Разброс урона
	 * _name - Имя моба
	 * type - тип атаки моба
	 */
	Mob(int _health, int _magicResistance, int _shockResistance, int _damage, int _spreadDamage, string _name, mobType type);
	int takePhysicalDamage(Player* player, attackDir dir);
	int takeMagicalDamage(Player* player, attackDir dir);
};

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

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

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ятрогенная патология врачебные ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Error at loading of ippcv library photoshop 2021 решение ошибки