小编Ror*_*ory的帖子

获取错误C3352(指定的函数与委托类型不匹配),即使函数似乎与委托类型匹配

以下是编译时的确切错误消息:

错误C3352: 'double MyNamespace :: MyRefClass :: MyFunction(const std :: vector <_Ty>&,std :: vector <_Ty>&,void*)':指定的函数与委托类型'double(const)不匹配std :: vector <_Ty>&,std :: vector <_Ty>&,void*)'

MyFunction 是引用类中的私有函数 MyRefClass

当我尝试使用代码创建MyDelegate在同一引用类中声明的私有委托的实例时,引发的错误显示出来:

MyDelegate^ del = gcnew MyDelegate(&MyRefClass::MyFunction);
Run Code Online (Sandbox Code Playgroud)

据我所知,函数的签名MyFunctionWrapper与委托匹配,所以我不确定导致错误的原因.

为完整起见,(私有)函数签名是:

double MyFunction(const std::vector<double> &x, std::vector<double> &grad, void *data)
Run Code Online (Sandbox Code Playgroud)

和(私人)代表声明是:

delegate double MyDelegate(const std::vector<double> &x, std::vector<double> &grad, void *data);
Run Code Online (Sandbox Code Playgroud)

c++-cli

7
推荐指数
1
解决办法
2671
查看次数

将System :: array转换为std :: vector

有没有人知道将CLI/.NET System ::数组转换为C++ std :: vector的简单方法,除了按元素方式进行操作外?

我正在CLI/C++中编写一个包装器方法(SetLowerBoundsWrapper,它接受System :: array作为参数),并将等效的std :: vector传递给本机C++方法(set_lower_bounds).目前我这样做如下:

using namespace System;

void SetLowerBoundsWrapper(array<double>^ lb)
{
    int n = lb->Length;
    std::vector<double> lower(n); //create a std::vector
    for(int i = 0; i<n ; i++)
    {
        lower[i] = lb[i];         //copy element-wise
    } 
    _opt->set_lower_bounds(lower);
}
Run Code Online (Sandbox Code Playgroud)

.net c++-cli wrapper

6
推荐指数
1
解决办法
6688
查看次数

如何隐藏y轴?

我在MATLAB中绘制一个水平箱图 - boxplot(y, group,'orientation','horizontal')然后使用隐藏y轴set(gca,'box','off','ycolor','w').

它在屏幕上看起来很好 - 只有底部的x轴可见.但是每当我将图形保存到文件时,使用print()函数或matlabfrag.m,左边的y轴重新出现在输出文件中(尽管它没有显示在MATLAB的图形可视化中).

如何隐藏这个Y轴?

matlab matlab-figure yaxis

6
推荐指数
3
解决办法
1万
查看次数

每个C#控制台应用程序打印"系统找不到指定的路径"

每次我运行C#控制台应用程序(从Visual C#Express 2010或Visual Studio Ultimate 2010)时,第一行输出是

该系统找不到指定的路径

,即使我的程序没有做任何事情,也没有指定任何路径.为什么会这样?有没有办法检查它正在寻找的路径是什么?程序运行正常.我试图捕获System.IO.DirectoryNotFoundException但无法找出放置try/catch块的位置.

我正在运行Windows 7 x64,构建控制台应用程序,并尝试了所有不同的平台目标(x86,x64,AnyCPU),我可以在Visual Studio中,总是得到相同的

我一直有其他一些问题并且有预感,这可能与那些问题有关,这就是为什么我想弄明白这一点.谢谢!

下面是Visual Studio生成的z .csproj文件(此项目显示我从命令行运行或从VS运行时描述的有问题的行为)

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{04EC9A5E-74D8-4A5F-BCD3-05D9B6CA1477}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>UsingNLOpt</RootNamespace>
    <AssemblyName>UsingNLOpt</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" …
Run Code Online (Sandbox Code Playgroud)

.net c#

5
推荐指数
1
解决办法
1538
查看次数

CLI/C++:void*到System :: Object

这个SO帖子也是一个类似的问题,我一直无法解决我的问题.我在这里添加了一些代码,希望能够帮助某人将其他帖子所传达的信息带回家.

我想编写一个CLI/C++方法,它可以将void指针作为参数,并返回它指向的托管对象(我知道它的类型).我有一个托管结构:

public ref struct ManagedStruct { double a; double b;};
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写的方法,它将一个指向托管结构的void指针作为参数并返回结构.

ManagedStruct^ VoidPointerToObject(void* data)
{   
    Object^ result = Marshal::PtrToStructure(IntPtr(data), Object::typeid);
    return (ManagedStruct^)result;
}
Run Code Online (Sandbox Code Playgroud)

这里调用该方法:

int main(array<System::String ^> ^args)
{   
    // The instance of the  managed type is created:
    ManagedStruct^ myData = gcnew ManagedStruct();
    myData->a = 1;  myData->b = 2;      

    // Suppose there was a void pointer that pointed to this managed struct
    void* voidPtr = &myData;

    //A method to return the original struct from the void pointer
    Object^ …
Run Code Online (Sandbox Code Playgroud)

pointers c++-cli command-line-interface

4
推荐指数
1
解决办法
8413
查看次数