gpt4 book ai didi

c++ - 如何修复错误 C4930 : 'AMyStaticMeshActor a(void)' : prototyped function not called (was a variable definition intended?)

转载 作者:行者123 更新时间:2023-11-28 00:14:53 30 4
gpt4 key购买 nike

我不明白,当我想用​​ AMyStaticMeshActor 类型初始化对象时如何修复错误:

AMyStaticMeshActor a();

错误是:

error C4930: 'AMyStaticMeshActor a(void)': prototyped function not called (was a variable definition intended?)

MyStaticMeshActor.h:

#pragma once

#include "Engine/StaticMeshActor.h"
#include "MyStaticMeshActor.generated.h"

/**
*
*/
UCLASS()
class MYGAME_API AMyStaticMeshActor : public AStaticMeshActor
{
GENERATED_BODY()


public:
AMyStaticMeshActor();
AMyStaticMeshActor(FVector location);

// Called when the game starts or when spawned
virtual void BeginPlay() override;

// Called every frame
virtual void Tick(float DeltaSeconds) override;

UPROPERTY(EditAnywhere, Category = General)
TSubclassOf<class AActor> WhatToSpawn;

UPROPERTY(Category = Block, VisibleDefaultsOnly, BLueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class UBlueprint* Crystal;

};

MyStaticMeshActor.cpp:

#include "MyGame.h"
#include "MyStaticMeshActor.h"


AMyStaticMeshActor::AMyStaticMeshActor() {

}

AMyStaticMeshActor::AMyStaticMeshActor(FVector location) {

}

// Called when the game starts or when spawned
void AMyStaticMeshActor::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void AMyStaticMeshActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

如何解决这个问题?

最佳答案

这被称为 most vexing parse .

AMyStaticMeshActor a();

它不会创建类型为 AMyStaticMeshActor 的名为 a 的变量,它声明了一个名为 a 的函数,该函数返回一个 AMyStaticMeshActor 并且不带任何参数。

要解决这个问题,只需删除括号:

AMyStaticMeshActor a;
AMyStaticMeshActor a{}; //or in C++11

关于c++ - 如何修复错误 C4930 : 'AMyStaticMeshActor a(void)' : prototyped function not called (was a variable definition intended?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31005571/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com