R
rsa_net_newbie
Hi there,
I have a Managed C++ object (in a DLL) which has a method that is
defined like ...
Generic::List<String^>^ buildList(String^ inParm)
Now, when I compile it, I get "warning C4172: returning address of
local variable or temporary". In good old 'C', that would indicate
that a 'static' was missing from the declaration of the returned value.
How do I avoid this issue in Managed C++?
It does appear to work and fill the array - but I guess the data may
get garbage collected at any point and suddenly disappear.
Any help greatly appreciated.
Cheers,
Paul
(Functions below)
Calling Program
===========
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Configuration;
using XYZ.ABC;
namespace TestDriver
{
class Program
{
static void Main(string[] args)
{
tObject testObject = null;
Console.WriteLine("Start");
testObject = new tObject(7);
IList<String> returnList = new List<String>();
returnList = testObject.buildList("information");
foreach (String thisValue in returnList)
{
Console.WriteLine("List item: [{0}]", thisValue);
}
Console.WriteLine("Finish");
Console.ReadLine();
}
}
}
AND
Called Object
==========
#include "stdafx.h"
#pragma once
using namespace System;
using namespace System::Globalization;
using namespace System::Collections::Generic;
using namespace System::Collections;
using namespace System::Runtime::InteropServices;
namespace XYZ {
namespace ABC {
public ref class tObject
{
private:
static int item_count = 0;
public:
tObject(int total_items) { item_count = total_items; }
virtual ~tObject() { item_count = 0; }
Generic::List<String^>^ buildList(String^ inParm)
{
int counter;
List<String^> ResultList = gcnew List<String^>();
for(counter = 0; counter < item_count; counter++)
{
String^ Item;
Item = gcnew String("list item content " + inParm + " " + (counter
+ 1));
ResultList.Add(Item);
}
return %ResultList;
}
};
}
}
I have a Managed C++ object (in a DLL) which has a method that is
defined like ...
Generic::List<String^>^ buildList(String^ inParm)
Now, when I compile it, I get "warning C4172: returning address of
local variable or temporary". In good old 'C', that would indicate
that a 'static' was missing from the declaration of the returned value.
How do I avoid this issue in Managed C++?
It does appear to work and fill the array - but I guess the data may
get garbage collected at any point and suddenly disappear.
Any help greatly appreciated.
Cheers,
Paul
(Functions below)
Calling Program
===========
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Configuration;
using XYZ.ABC;
namespace TestDriver
{
class Program
{
static void Main(string[] args)
{
tObject testObject = null;
Console.WriteLine("Start");
testObject = new tObject(7);
IList<String> returnList = new List<String>();
returnList = testObject.buildList("information");
foreach (String thisValue in returnList)
{
Console.WriteLine("List item: [{0}]", thisValue);
}
Console.WriteLine("Finish");
Console.ReadLine();
}
}
}
AND
Called Object
==========
#include "stdafx.h"
#pragma once
using namespace System;
using namespace System::Globalization;
using namespace System::Collections::Generic;
using namespace System::Collections;
using namespace System::Runtime::InteropServices;
namespace XYZ {
namespace ABC {
public ref class tObject
{
private:
static int item_count = 0;
public:
tObject(int total_items) { item_count = total_items; }
virtual ~tObject() { item_count = 0; }
Generic::List<String^>^ buildList(String^ inParm)
{
int counter;
List<String^> ResultList = gcnew List<String^>();
for(counter = 0; counter < item_count; counter++)
{
String^ Item;
Item = gcnew String("list item content " + inParm + " " + (counter
+ 1));
ResultList.Add(Item);
}
return %ResultList;
}
};
}
}