Vector does not name a type

Я довольно новичок в C ++, & У меня проблема с объявлением векторов в качестве переменной класса. Я заставил их работать в другом месте моего кода, используя похожую стратегию, но мне не нравится мой заголовочный файл.

Я прокомментировал строки, которые GCC указывает на проблему.

Вот скриншот ошибки в моей IDE, если это дает больше подсказок.

Решение

Единственная проблема, с которой я столкнулся при компиляции вашего кода, это то, что вы используете Course в Entrant класс, но у вас нет определения для Course в таком случае.

Если вы перешлите объявить Course чуть выше Entrant вот так:

Затем ваш код компилируется, в соответствии с этим живой пример

Другие решения

Ты обманываешь 😉 . Код, который вы дали нам, имеет std::vector , который работает, в то время как код на вашем скриншоте имеет vector который не работает (компилятор не знает, где его взять).

Решение: измените код для использования std::vector ,

i have this error in the title: here class declaration of variables and prototypes of function

Whats wrong with the prototype of function in first block? Why vector is told to be not a type? I would be grateful if u could help me to find out this.

2 Answers 2

Change your header file to:

Your header file does not include the vector header. Add a #include to the beggining.

Besides, you should refer to it as std::vector instead of vector , since it belongs to the std namespace. Declaring using namespace x; in header files is not a good practice, as it will propagate to other files as well.

Читайте также:  Le eco le 2 x527 прошивка

Not the answer you’re looking for? Browse other questions tagged c++ vector prototype or ask your own question.

Linked

Related

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.1.17.35809

I’m having lots of errors in my final project (a poker and black jack sim). I’m using a vector to implement the "hands" in the blackJack class, and I’m using a structured data type declared in another class, which is publicly inherited. The error I’m worried about is the compiler I’m using telling me that I’m not declaring a type in the vector.

blackJack header file:

card header file (this is the class black jack inherits from):

4 Answers 4

You forgot to add std:: namespace prefix to vector class name.

everywhere qualify it by std::

in your cpp file.

You have to do this because vector is defined in the std namespace and you do not tell your program to find it in std namespace, you need to tell that.

Rate this post

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *