Использование Enum внутри класса в качестве параметра функции вне его классаC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Гость
 Использование Enum внутри класса в качестве параметра функции вне его класса

Сообщение Гость »


У меня есть Enum, который я уже использую для множества других целей, однако в этих случаях я использую Enum как общедоступную переменную класса, что означает, что я могу получить к нему доступ как

Код: Выделить всё

EntityManager.FAll
.
However, in the new use case I have for it I want to use the Enum in that class as a function parameter of another class's function like

Код: Выделить всё

CEntityManager::EBroadcastTypes
.
But no matter what I try, when I try to compile the code this always fails telling me that either when using the scope operator I need to be using a Class or Namespace even though this is a class (error code: C2653), or that

Код: Выделить всё

EBroadcastTypes
isnt a known identifier (error code: 2061).
Just to further 'visualize' this, as an example.
I want to use this Enum for 'filtering channels' when Ray Casting, so that I can either only check for specific Wanted Entities.

Код: Выделить всё

EntityManager.h

class CEntityManager
{
public:

CEntityManager();

~CEntityManager();

private:
// Prevent use of copy constructor and assignment operator (private and not defined)
CEntityManager( const CEntityManager& );
CEntityManager& operator=( const CEntityManager& );

/////////////////////////////////////
//  Public interface
public:

enum EBroadcastTypes
{
FAll,
FTank,
FShell,
FDynamic, // Any Entity that can movement on update (ie. Tank and Shells)
FStatic, // Any Entity that never moves (ie. Enivronment)
};

struct BroadcastFilter
{
EBroadcastTypes type;
vector channels;
};

vector
m_BroadcastFilters;

vector GetChannelsOfFilter(EBroadcastTypes Type)
{
for (const auto& BroadcastFilter : m_BroadcastFilters)
{
if (BroadcastFilter.type == Type)
{
return BroadcastFilter.channels;
}
}
}

};

Код: Выделить всё

ProjectName.cpp

#include "EntityManager.h"
#include "CRayCasting.h"

CEntityManager EntityManager;

// Primary Update(tick) function
Update()
{
if(true)// On Some condition
{
TFloat32 range = 400.0f
CRay ray;
ray.m_Origin = CVector3(0,0,0);
ray.m_Direction = CVector3(0,0,0);
HitResult Hit = RayCast(ray, EntityManager.FAll, range);

// Do something with Hit ...
}
}
RayCast file doesn't contain a class, simply functions that fall under the same category that would be used across multiple points/classes throughout the code.

Код: Выделить всё

CRayCasting.h

#include "EntityManager.h"

class CEntity;

struct HitResult
{
CVector3 m_hitPosition;
CEntity* m_hitEntity;
};

struct CRay
{
CVector3 m_Origin;
CVector3 m_Direction;
};

// Simple RayCast, checking intersection with any Entity,
// Checks against all entities that belong to this Channel.
HitResult RayCast(CRay ray, CEntityManager::EBroadcastTypes WantedChannel); // This is line 50 in the output/error messages

Код: Выделить всё

CRayCasting.cpp

#include "CRayCasting.h"

// Get Access to the Entity Manager
extern CEntityManager EntityManager;

// Simple RayCast, checking intersection with any Entity - Checks whether entity is of wanted Type/Channel
HitResult RayCast(CRay ray, CEntityManager::EBroadcastTypes WantedChannel)
{
HitResult closestIntersection;

vector channels = EntityManager.GetChannelsOfFilter(static_cast(WantedChannel));

// Do the Raycast

return closestIntersection;
}
So is there any way to actually use the Enum like this?
Tried including the header as well as forward declaring both the class and enum (the compiler then told me it didn't know what those forwards are).
EDIT:
I accidentally used the wrong operator (. вместо ::) для вызова функции RayCast, как я написал вопрос.
Но это даже не тот случай, когда компилятор выдает мне ошибку.
Ошибка происходит внутри заголовочного файла при объявлении функции.
Здесь также указаны коды ошибок в лучшем формате:

Код: Выделить всё

Error C2653 'CEntityManager': is not a class or namespace name ProjectName E:\Project\Source\Physics\CRayCasting.h 50

Код: Выделить всё

Error C2061 syntax error: identifier 'EBroadcastTypes' ProjectName E:\Project\Source\Physics\CRayCasting.h 50
EDIT 2:
As suggested I included pretty much everything of the code relevant to the use of the enum from that class in my function. If there is anything missing to count this as MRE please let me know, my first time doing this.
Additionally added the compiler output as suggested (Not sure if I should do the whole thing or only relevant parts, but here is everything for now):
https://pastebin.com/Sjyg5nKw


Источник: https://stackoverflow.com/questions/781 ... -its-class
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Как создать член ENUM в родительском классе ENUM? Для методов класса, ссылающихся на значение по умолчанию
    Anonymous » » в форуме Python
    0 Ответы
    18 Просмотры
    Последнее сообщение Anonymous
  • Как создать член ENUM в родительском классе ENUM? Для методов класса, ссылающихся на значение по умолчанию
    Anonymous » » в форуме Python
    0 Ответы
    15 Просмотры
    Последнее сообщение Anonymous
  • Как я могу заставить typing.overload работать с enum.Enum?
    Anonymous » » в форуме Python
    0 Ответы
    45 Просмотры
    Последнее сообщение Anonymous
  • Кастинг-класс> до Class>
    Anonymous » » в форуме JAVA
    0 Ответы
    48 Просмотры
    Последнее сообщение Anonymous
  • Кастинг-класс> до Class>
    Anonymous » » в форуме JAVA
    0 Ответы
    65 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C++»