Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.87/15: Рейтинг темы: голосов - 15, средняя оценка - 4.87
296 / 125 / 106
Регистрация: 30.10.2015
Сообщений: 690
1

Was not declared in this scope (Классы)

20.02.2016, 23:25. Показов 2978. Ответов 3
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Добрый вечер! Получаю вот такие ошибки:

Bash
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
Class.h:3:6: error: ‘Hero’ has not been declared
 void Hero::view (int value)
      ^
Class.h: In function ‘void view(int)’:
Class.h:7:13: error: ‘view_’ was not declared in this scope
     strcpy (view_, "Hunter");
             ^
Class.h:8:5: error: ‘life_’ was not declared in this scope
     life_ = 10000;
     ^
Class.h:9:5: error: ‘armor_’ was not declared in this scope
     armor_ = 2000;
     ^
Class.h:10:5: error: ‘attack_’ was not declared in this scope
     attack_ = 300;
     ^
Class.h:11:5: error: ‘speed_’ was not declared in this scope
     speed_ = 100; 
     ^
Class.h:15:13: error: ‘view_’ was not declared in this scope
     strcpy (view_, "Soldier");
             ^
Class.h:16:5: error: ‘life_’ was not declared in this scope
     life_ = 1000;
     ^
Class.h:17:5: error: ‘armor_’ was not declared in this scope
     armor_ = 300;
     ^
Class.h:18:5: error: ‘attack_’ was not declared in this scope
     attack_ = 50;
     ^
Class.h:19:5: error: ‘speed_’ was not declared in this scope
     speed_ = 50;
     ^
project_one.cpp
C++
1
2
3
4
5
6
#include <iostream>
#include "Class.h"
 
int main (void){
  return 0;
}
Class.h
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Hero.h"
 
class Hero{
  private:
    int life_,
        armor_,
        attack_,
        speed_;
 
    char view_[20];
  public:
    void view (int);
};
Hero.h
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstring>
 
void Hero::view (int value)
{
  if (value == 1)
  {
    strcpy (view_, "Hunter");
    life_ = 10000;
    armor_ = 2000;
    attack_ = 300;
    speed_ = 100;
  }
  if (value == 2)
  {  
    strcpy (view_, "Soldier");
    life_ = 1000;
    armor_ = 300;
    attack_ = 50;
    speed_ = 50;
  }
}
В чем проблема???
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
20.02.2016, 23:25
Ответы с готовыми решениями:

'arr' was not declared in this scope 'sum' was not declared in this scope такие вот ошибки.(
#include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;ctime&gt; using namespace std; int main () { ...

Список с дробями: Variable or field 'input' declared void 'pd' was not declared in this scope
почему не нравится 1ая функция? #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; struct rational_fraction...

Was not declared in this scope
вот мой класс, пишет вот такие ошибки: error: 'pow' was not declared in this scope, так же само с...

'mean' was not declared in this scope
здравствуйте,наткнулся на статью,где человек строит лодку на автопилоте,но у меня есть проблема...

3
Эксперт С++
8739 / 4317 / 960
Регистрация: 15.11.2014
Сообщений: 9,760
21.02.2016, 02:22 2
Цитата Сообщение от Nemovok Посмотреть сообщение
#include "Hero.h"
class Hero{
заменить на:

C++
1
2
3
#pragma once"
 
class Hero{
Цитата Сообщение от Nemovok Посмотреть сообщение
#include <cstring>
void Hero::view (int value)
заменить на:

C++
1
2
3
4
#include <cstring>
#include "Hero.h"
 
void Hero::view (int value)
1
296 / 125 / 106
Регистрация: 30.10.2015
Сообщений: 690
21.02.2016, 10:32  [ТС] 3
Вы хотите что бы я в Hero.h подключил Hero.h???
Цитата Сообщение от hoggy Посмотреть сообщение
заменить на:
C++
1
2
3
#include <cstring>
#include "Hero.h"
void Hero::view (int value)
0
nd2
3437 / 2816 / 1249
Регистрация: 29.01.2016
Сообщений: 9,426
21.02.2016, 11:00 4
Class.h переименуй в Hero.h (убери из него #include "Hero.h"). Реализации методов Hero вынеси в отдельный .cpp, там и в main подключи Hero.h.
1
21.02.2016, 11:00
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
21.02.2016, 11:00
Помогаю со студенческими работами здесь

Was not declared in this scope!
Уже надоела данная ошибка! work.cpp:34: ошибка: 'ui' was not declared in this scope ...

Gets was not declared in this scope, why?
#include &lt;stdio.h&gt; //показываю что объявил char p; void *recvmg(void *sock) { struct...

'...' was not declared in this scope
Доброго времени суток. Столкнулся с одной проблемой при создании класса: имеется описание класса :...

Was not declared in this scope
Можете подсказать как исправить. При компиляции выдает 'strLen' was not declared in this scope ...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
4
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru