|
already tried #pragma make public (mynativestruct)
Here is my c++-cli code
ClassLibraryAT::Class1^ matClass = gcnew ClassLibraryAT::Class1() ;
matClass->M_AT(&cparams,&input,&numcontacts,&contact,&ecdata);
the 'input' struct in the argument list is comprised of ints doubles, stuff like that. Not a managed struct. It's saying the candidate function M_AT is not accessible. How do I resolve this? thanks, sb
|
|
|
|
|
bonosa wrote: It's saying the candidate function M_AT is not accessible. How do I resolve this? Make sure that M_AT is a public method.
Use the best guess
|
|
|
|
|
thanks Richard. It is a public method and shows up in the intellisense.
|
|
|
|
|
I'm afraid that tells us nothing; try looking at the actual class definition or documentation.
Use the best guess
|
|
|
|
|
hi Developers,
I am trying to get the result of this code
printf( "sqrt(36.0) = %f", sqrt(36.0) );
The mystry is that, If i have include math.h file, than I am getting proper result, bu I haven't, I am getting the result 0.000000
can you please help me out
Thanks
Amrit Agrawal
|
|
|
|
|
I just tried without including math.h and it works fine. Try seeing what the actual definition of sqrt is when you have not included the header.
Use the best guess
|
|
|
|
|
Hello y'all...I am want to use IO stream redirection to reuse my previous program to calculate and equation from batch file...Can U help me on how am I to use this io stream to reuse my program
|
|
|
|
|
Your question is not very clear, please explain your problem in more detail.
|
|
|
|
|
I developed a program to convert celcius to kelvin and one to convert kelvin to Fahrenheit...now what I want to do is convert celcius to Fahrenheit reusing my programs with IO stream redirection,with input and output on batch files...clear?
|
|
|
|
|
Why not just do everything in one single program using a class to do the conversions?
|
|
|
|
|
aint gonna get an exception error thrown at me for trying different methods am I?but thanks anyway
|
|
|
|
|
Dirquez Marquez wrote: aint gonna get an exception error thrown at me for trying different methods am I?
|
|
|
|
|
never mind its fine thanks
|
|
|
|
|
|
The answer given in that question is correct. There is no C++ keyword equivalent to using() from C# because C++/CLI has deterministic finalization. When the object goes out of scope and there are no more references, it will be disposed.
|
|
|
|
|
Hi Developers,
I am trying to run this chunk of code.
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit;
printf("%d\n", sizeof(bit));
I am getting value "4". I am running this program in 32 bit machine using Microsoft Visual C++ complier.
Can you please clarify about the result.
|
|
|
|
|
You have 9 bits in your field and the default alignment of object code in 32bit architecture is word (32 bit) boundaries. So your structure item will be stored in a 32bit word. You could make it smaller by using a #pragma pack [^] statement.
By the way, this is the managed C++ forum, your questions really belong in http://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspx[^].
|
|
|
|
|
Thanks a lot Rechard.. for the clarification
|
|
|
|
|
Hi Developers,
I have read about sopen() function to open a file in shared mode. Here is the code.
#include <stdio.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <io.h>
#include <share.h>
void main(void);
void main(void)
{
int file_handle;
/* Note that sopen() is not ANSI compliant */
file_handle = sopen"D:\\Study\\file.txt", O_RDWR, SH_DENYNO);
close(file_handle);
}
I am getting "-1" on file_handle and program is also getting crash.
Can u please help me out.
|
|
|
|
|
Check the documentation.
A hint: You need to check errno to get the reason for the failure. Compare that result to the items in errno.h (ex. EACCES, EEXIST, etc..).
|
|
|
|
|
Hi,
This is possible, when the file mentioned is not present in the corresponding path or the file name is wrong you get the file handle as -1.
And its crashing because, you are trying to close a invalid file handle in close() api.
|
|
|
|
|
How to call a static libray in a dll?
I am using Visual C++ .
3X
heartofdra
|
|
|
|
|
LongFangFang wrote: How to call a static libray in a dll? What exactly are you trying to do?
|
|
|
|
|
I have a third party unmanaged c++ library.
I created a managed c++ wrapper for it since I need to call it from c# code. Problem is one of native c++ functions passes an int by reference. I do not know how to route this through the managed wrapper to the c# code. For example
class A //unmnaged SDK class
{
public:
void Foo(int& i);
}
//managed c++ wrapper
public ref class A_Wrapper
{
public:
A_Wrapper() {_unmanaged = new A();};
~A_Wrapper() {delete unmanaged; };
void Foo(int& i) { _unmanaged->Foo(i)};
private:
A * _unmanaged;
}
In my c# (yes #) code I try to call A_Wrapper::Foo() but I get compile errors
c# code:
public static void Main()
{
A_Wrapper aw = new A_Wrapper();
int id = 0;
aw.Foo(&id);
}
error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
I don't really want to wrap it in an unsafe {} block. How do I route the pass by reference from c++ to c# properly?
Update: Answered. (I figured it out) I had to change the wrapper class to use tracking references, i.e.
//managed c++ wrapper
public ref class A_Wrapper
{
public:
A_Wrapper() {_unmanaged = new A();};
~A_Wrapper() {delete unmanaged; };
void Foo(int% i)
{
int ret=0;
_unmanaged->Foo(ret);
i = ret;
};
private:
A * _unmanaged;
}
c# code:
public static void Main()
{
A_Wrapper aw = new A_Wrapper();
int id = 0;
aw.Foo(ref id);
}
|
|
|
|
|
Four programs (listings 19.4, 19.5, 19.6 and 19.7) in the book
"Teach Yourself C++ in 21 Days" by Jesse Liberty and Bradley Jones
do not compile. The first of these programs is as follows:
//Listing 19.4 Using Operator ostream
#include <iostream>
using namespace std;
const int DefaultSize = 10;
class Animal
{
public:
Animal(int);
Animal();
~Animal() {}
int GetWeight() const { return itsWeight; }
void Display() const { cout << itsWeight; }
private:
int itsWeight;
};
Animal::Animal(int weight):
itsWeight(weight)
{}
Animal::Animal():
itsWeight(0)
{}
template <class T> // declare the template and the parameter
class Array // the class being parameterized
{
public:
// constructors
Array(int itsSize = DefaultSize);
Array(const Array &rhs);
~Array() { delete [] pType; }
// operators
Array& operator=(const Array&);
T& operator[](int offSet) { return pType[offSet]; }
const T& operator[](int offSet) const
{ return pType[offSet]; }
// accessors
int GetSize() const { return itsSize; }
// template <class T>
friend ostream& operator<< (ostream&, Array<T>&);
private:
T *pType;
int itsSize;
};
template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
for (int i = 0; i < theArray.itsSize; i++)
{
output << "[" << i << "] " << theArray[i] << endl;
}
return output;
}
// implementations follow...
// implement the Constructor
template <class T>
Array<T>::Array(int size):
itsSize(size)
{
pType = new T[size];
for (int i = 0; i < size; i++)
pType[i] = 0;
}
// copy constructor
template <class T>
Array<T>::Array(const Array &rhs)
{
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i = 0; i < itsSize; i++)
pType[i] = rhs[i];
}
// operator=
template <class T>
Array<T>& Array<T>::operator=(const Array &rhs)
{
if (this == &rhs)
return *this;
delete [] pType;
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i = 0; i < itsSize; i++)
pType[i] = rhs[i];
return *this;
}
int main()
{
bool Stop = false; // flag for looping
int offset, value;<pre lang="c++"></pre>
Array<int> theArray;
while (Stop == false)
{
cout << "Enter an offset (0-9) ";
cout << "and a value. (-1 to stop): ";
cin >> offset >> value;
if (offset < 0)
break;
if (offset > 9)
{
cout << "***Please use values between 0 and 9.***\n";
continue;
}
theArray[offset] = value;
}
cout << endl << "Here's the entire array:" << endl;
cout << theArray << endl;
return 0;
}
Attempting to compile this program on Linux with g++ produces the
following message:
g++ -fpermissive list1904.cpp -o List19.4
list1904.cpp:45:52: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, Array<T>&)’ declares a non-template function [-Wnon-template-friend]
list1904.cpp:45:52: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)
/tmp/ccgXupn5.o: In function `main':
list1904.cpp text+0x102): undefined reference to `operator<<(std::ostream&, Array<int>&)'
collect2: error: ld returned 1 exit status
make: *** [List19.4] Error 1
I would very much appreciate any help in resolving this problem.
Thank you very much,
tim_mann
tcnm
-- modified 14-Dec-12 16:09pm.
|
|
|
|