首页 > 解决方案 > C++ Visual Studio Error: name followed by '::' must be a class or namespace name (DirectX 11)

问题描述

I dont understand what's wrong here

manager.h

#pragma once
class CManager
{

public:
static void Init();
static void Uninit();
static void Update();
static void Draw();

};

main.cpp

#include "main.h"
#include "manager.h"

...

CManager::Init(); //error here 

...

CManager::Update(); //error here


CManager::Draw(); //and here

But name followed by :: is already a class. Why does it show me an error?

标签: c++directx-11

解决方案


看起来你想调用你的函数,不是吗?如果我是对的,那么您需要先定义您的函数,然后才能调用它们。

class CManager
{

public:
    static void Init();
    static void Uninit();
    static void Update();
    static void Draw();

};

在这里,您只声明了它们。

您必须在类中定义它们:

class CManager
{

public:
    static void Init()
    {
        //Do something...
    }
    static void Uninit()
    {
        //...
    }
    static void Update()
    {
        //...
    }
    static void Draw()
    {
        //...
    }

};

...或在你的课外:

void CManager::Init()
{
    //Do something...
}
//and so on...

推荐阅读