c++ - Windows Universal App 8.1 C++/自定义类属性

标签 c++ windows-phone-8.1

我正在 Windows Phone 上开发应用程序。在 VS 模板项目中,有一个类 SampleDataSource 实现了应用程序的数据层。在类似的类中,我添加了一个具有我自己类类型的属性 (AccountData^ Account),并得到以下错误 LNK2001。谁能帮帮我?

[Windows::UI::Xaml::Data::Bindable]
public ref class AccountDataSource sealed
{
public:
    property Windows::Foundation::Collections::IObservableVector<AccountMessage^>^ Messages
    {
         Windows::Foundation::Collections::IObservableVector<AccountMessage^>^ get();
    }
    property AccountData^ Account
    {
         AccountData^ get();
    }
internal:
    AccountDataSource();
    static concurrency::task<AccountData^> GetAccount(Platform::String^ id);
private:
    AccountData^ _account;
    Platform::Collections::Vector<AccountMessage^>^ _messages;
    static AccountDataSource^ _accountDataSource;
};

错误:

Error   1   error LNK2001: unresolved external symbol "public: virtual class WindowsUniversalApp::Data::AccountData ^ __cdecl WindowsUniversalApp::Data::AccountDataSource::Account::
[WindowsUniversalApp::Data::__IAccountDataSourcePublicNonVirtuals::Account]::get(void)" (?get@?QAccount@__IAccountDataSourcePublicNonVirtuals@Data@WindowsUniversalApp@@1AccountDataSource@34@U$AAAP$AAVAccountData@34@XZ)
   C:\Users\xxx\Documents\Projects\Universal\WindowsUniversalApp\WindowsUniversalApp\WindowsUniversalApp.Windows\AccountDataSource.obj  WindowsUniversalApp.Windows

谢谢,

最佳答案

您说过 Messages 是一个带有 getter 的属性,但是您还没有在任何地方定义 getter。你需要一个函数体:

property longTypeName Messages { longTypeName get() { return _messages; } }

(当然你也可以把它放在CPP文件里)。

关于c++ - Windows Universal App 8.1 C++/自定义类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28255828/

相关文章:

C++20 显式默认相等运算符

c++ - 为什么 `std::make_shared` 使用 `-fno-rtti` 执行两个单独的分配?

c++ - 多维 vector 和指向 vector 的指针

c++ - 从字符串到 double 的转换 - 可能性和错误

c# - Cortana 回复而不是应用程序启动

c# - 使用 HttpClient 的进度信息

c++ - 如何修复 boost/asio c++ 异常错误?

c# - 检查 2 种类型是否相同

c# - 在 Windows Phone 8.1 中更新动态磁贴

c# - Windows Phone 8.1 中的后台线程