我创建了Windows运行时组件(名称空间:动物),我想覆盖Platform :: String :: ToString方法。在Windows运行时组件中重写ToString
Dog.h
#pragma once
namespace Animal
{
public ref struct Dog sealed
{
private:
String^ _name; // Yes, it's private
public:
Dog();
//String^ ToString();
virtual String^ ToString() override { } // I've found this in internet
};
}
Dog.cpp
#include "pch.h"
#include "Dog.h"
using namespace Animal;
using namespace Platform;
String^ _name;
Dog::Dog()
{
}
String^ Dog::ToString()
{
return _name;
}
和所有的编译错误是Dog.h在 “虚拟字符串^的ToString()重写{}”:
· Error C2433 'Animal::Dog::String': 'virtual' not permitted on data declarations
· Error C4430 missing type specifier - int assumed. Note: C++ does not support · default-int
· Error C2143 syntax error: missing ';' before '^'
· Error C2334 unexpected token(s) preceding '{', skipping apparent function body
在你的.h文件中使用Platform :: String,所以你不需要使用'namespace Platform;'来作为范围。并修复你的.cpp文件中的错误。 –
不要在问题中提出答案。问题在于这个问题。答案在答案部分。 –