C++ 读取访问冲突这是nullptr错误,初始化不正确?

C++ 读取访问冲突这是nullptr错误,初始化不正确?,c++,visual-studio,vector,uwp,c++-cx,C++,Visual Studio,Vector,Uwp,C++ Cx,我正在使用通用windows平台(UWP)用C++/CX编写一个程序。我是新的编程,更熟悉常规C++。这是我第一次制作UWP应用程序 该程序包含一个名为Dress_pack的类,我在MainPage.xaml.cpp文件中创建了一个名为d的实例 套装d(“,”,“) Dress_pack有一个名为meas_v的成员,它是类型为Platform::String^的IVector。这是我的Dress_pack类构造函数: Dress_pack::Dress_pack(Platform::String

我正在使用通用windows平台(UWP)用C++/CX编写一个程序。我是新的编程,更熟悉常规C++。这是我第一次制作UWP应用程序

该程序包含一个名为Dress_pack的类,我在MainPage.xaml.cpp文件中创建了一个名为d的实例

套装d(“,”,“)

Dress_pack有一个名为meas_v的成员,它是类型为Platform::String^的IVector。这是我的Dress_pack类构造函数:

Dress_pack::Dress_pack(Platform::String^ plant = "", Platform::String^    prog = "", Platform::String^ robot = ""){
plant_no = plant; 
prog_no = prog;
robot_no = robot;
Windows::Foundation::Collections::IVector<Platform::String^>^ meas_v = ref new Platform::Collections::Vector<Platform::String^>();
Windows::Foundation::Collections::IVector<Platform::String^>^ iss_dis_v = ref new Platform::Collections::Vector<Platform::String^>();}
我的主页.xaml.h看起来像:

#pragma once

#include "MainPage.g.h"

namespace Project_1
{

public ref class MainPage sealed
{
public:
    MainPage();

};  

}
我的连衣裙套装的页眉包含:

#pragma once
ref class Dress_pack sealed
{

public:
    property Platform::String^ plant_no;
    property Platform::String^ prog_no;
    property Platform::String^ robot_no;
    property Windows::Foundation::Collections::IVector<Platform::String^>^ meas_v; property Windows::Foundation::Collections::IVector<Platform::String^>^ iss_dis_v;

//constructor
Dress_pack(Platform::String^ plant, Platform::String^ prog, Platform::String^ robot);

};
#pragma一次
ref类服装包装密封
{
公众:
物业平台::字符串^plant\u编号;
属性平台::字符串^prog\u no;
属性平台::字符串^robot\u编号;
属性窗口::基础::集合::IVector^meas\u v;属性窗口::基础::集合::IVector^iss\u dis\u v;
//建造师
服装套装(平台::字符串^plant,平台::字符串^prog,平台::字符串^robot);
};
但是在运行时,抛出错误
异常:读取访问冲突这是null ptr
发生在
d.meas_v->Append(“dk”)


在调试期间,我可以看到meas_v包含值nullptr,这似乎是问题的根源。我不知道为什么会这样。我的向量初始化错误了吗?是其他问题吗?朝正确的方向推动会有所帮助。如果您需要我发布更多代码来理解问题,也请告诉我。谢谢

在构造函数中创建两个新的局部变量,它们恰好与字段同名


此外,对于
Platform::String
(使用
L
前缀强制UCS2),您应该使用
L“bla”
字符串。

源代码通常比解释代码的外观更容易、更快速地解析。
ref new
意味着此指针正在被引用计数(因此被垃圾收集)-您没有在itI上调用
delete[]
,我不认为您应该
delete
托管对象。特别是,在
IVector
上删除[]
看起来非常错误。哦!好的,我已经移除了我的析构函数。非常感谢。原来的问题仍然存在。如果没有看到问题,我们无法帮助您。(您还应该能够通过调试代码找出引发异常的确切原因)
#pragma once
ref class Dress_pack sealed
{

public:
    property Platform::String^ plant_no;
    property Platform::String^ prog_no;
    property Platform::String^ robot_no;
    property Windows::Foundation::Collections::IVector<Platform::String^>^ meas_v; property Windows::Foundation::Collections::IVector<Platform::String^>^ iss_dis_v;

//constructor
Dress_pack(Platform::String^ plant, Platform::String^ prog, Platform::String^ robot);

};