473,614 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VC++ error C2662: cannon convert 'this' pointer...

I am having an issue with some VC++ I am writing. I have a struct and
I'm trying to call a function from it from a function in another
object.

here is the struct....
Expand|Select|Wrap|Line Numbers
  1. struct JNI_Interface
  2. {
  3. JavaVM *jvm;       /* denotes a Java VM */
  4. JNIEnv *env;       /* pointer to native method interface */
  5. //static jobject phone_obj;   // phone object to make JNI calls to PTF
  6. with
  7.  
  8. int jni_startJVM();
  9. int jni_checkException(char* jni_call) const;
  10. int jni_startCom() const;
  11. };
  12.  
here are the function defs...
Expand|Select|Wrap|Line Numbers
  1. JNI_Interface::jni_startCom() const
  2. {
  3. const char* phone_class_name = "phonetest/phone/synergy/SynergyPhone";
  4. // class of phone to use
  5. .....
  6. }
  7.  
here is the call...

Expand|Select|Wrap|Line Numbers
  1. in mobilePhone class...
  2. private:
  3. JNI_Interface ptfPhone;
  4.  
  5. mobilePhone::com_startCom()
  6. {
  7. // Added for JNI interface with PTF
  8. if(comPort == "PTF")
  9. {
  10. int teh_test = ptfPhone.jni_startCom();  // for testing
  11. return 0;
  12.  
  13. }
  14.  
I am getting this error...

[error]
error C2662: 'JNI_Interface: :jni_startCom' : cannot convert 'this'
pointer from 'JNI_Interface' to 'const JNI_Interface &'
[/error]

all the other online research I've done told me that if I changed these
functions to const that would fix this issue, but it still remains.
Any ideas?

Jul 26 '06 #1
10 5898
do******@gmail. com wrote:
I am having an issue with some VC++ I am writing. I have a struct and
I'm trying to call a function from it from a function in another
object.

here is the struct....
Expand|Select|Wrap|Line Numbers
  1. struct JNI_Interface
  2. {
  3. JavaVM *jvm;       /* denotes a Java VM */
  4. JNIEnv *env;       /* pointer to native method interface */
  5. //static jobject phone_obj;   // phone object to make JNI calls to PTF
  6. with
  7. int jni_startJVM();
  8. int jni_checkException(char* jni_call) const;
  9. int jni_startCom() const;
  10. };
  11.  

here are the function defs...
Expand|Select|Wrap|Line Numbers
  1. JNI_Interface::jni_startCom() const
  2. {
  3. const char* phone_class_name = "phonetest/phone/synergy/SynergyPhone";
  4. // class of phone to use
  5. ....
  6. }
  7.  

here is the call...

Expand|Select|Wrap|Line Numbers
  1. in mobilePhone class...
  2. private:
  3.   JNI_Interface ptfPhone;
  4. mobilePhone::com_startCom()
  5. {
  6. // Added for JNI interface with PTF
  7. if(comPort == "PTF")
  8. {
  9. int teh_test = ptfPhone.jni_startCom();  // for testing
  10. return 0;
  11. }
  12.  

I am getting this error...

[error]
error C2662: 'JNI_Interface: :jni_startCom' : cannot convert 'this'
pointer from 'JNI_Interface' to 'const JNI_Interface &'
[/error]

all the other online research I've done told me that if I changed
these functions to const that would fix this issue, but it still
remains. Any ideas?
Not enough information. Which line in the posted fragments does
the error message refer to?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 26 '06 #2
The error is thrown on the call to jni_startCom();

Expand|Select|Wrap|Line Numbers
  1. mobilePhone::com_startCom()
  2. {
  3. // Added for JNI interface with PTF
  4. if(comPort == "PTF")
  5. {
  6. int teh_test = ptfPhone.jni_startCom();  // THIS LINE THROWS THE
  7. ERROR!!!
  8. return 0;
  9.  
  10. }
  11.  
Jul 26 '06 #3
do******@gmail. com wrote:
I am having an issue with some VC++ I am writing. I have a struct and
I'm trying to call a function from it from a function in another
object.

here is the struct....
Expand|Select|Wrap|Line Numbers
  1. struct JNI_Interface
  2. {
  3.     JavaVM *jvm;       /* denotes a Java VM */
  4.     JNIEnv *env;       /* pointer to native method interface */
  5.     //static jobject phone_obj;   // phone object to make JNI calls to PTF
  6. with
  7.     int jni_startJVM();
  8.     int jni_checkException(char* jni_call) const;
  9.     int jni_startCom() const;
  10. };
  11.  

here are the function defs...
Expand|Select|Wrap|Line Numbers
  1. JNI_Interface::jni_startCom() const
  2. {
  3.     const char* phone_class_name = "phonetest/phone/synergy/SynergyPhone";
  4. // class of phone to use
  5. ....
  6. }
  7.  

here is the call...

Expand|Select|Wrap|Line Numbers
  1. in mobilePhone class...
  2. private:
  3.    JNI_Interface ptfPhone;
  4. mobilePhone::com_startCom()
  5. {
  6.     // Added for JNI interface with PTF
  7.     if(comPort == "PTF")
  8.     {
  9.         int teh_test = ptfPhone.jni_startCom();  // for testing
  10.         return 0;
  11.     }
  12.  

I am getting this error...

[error]
error C2662: 'JNI_Interface: :jni_startCom' : cannot convert 'this'
pointer from 'JNI_Interface' to 'const JNI_Interface &'
[/error]

all the other online research I've done told me that if I changed these
functions to const that would fix this issue, but it still remains.
Any ideas?
Firstly, which line of your code gives you this error exactly? You forgot to
indicate that.

Secondly, are you sure you reproduced the actual error message correctly?
Because frankly the way it looks in your message it doesn't make much sense
(could be VC++ compiler's fault, though).

--
Best regards,
Andrey Tarasevich
Jul 26 '06 #4
do******@gmail. com wrote:
The error is thrown on the call to jni_startCom();

Expand|Select|Wrap|Line Numbers
  1. mobilePhone::com_startCom()
  2. {
  3. // Added for JNI interface with PTF
  4. if(comPort == "PTF")
  5. {
  6. int teh_test = ptfPhone.jni_startCom();  // THIS LINE THROWS THE
  7. ERROR!!!
  8. return 0;
  9. }
  10.  
So, is 'ptfPhone' "const" or not? Is 'jni_startCom' member function
"const" or not? Read the FAQ 5.8 to understand why I am asking.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 26 '06 #5

Victor Bazarov wrote:
do******@gmail. com wrote:
The error is thrown on the call to jni_startCom();

Expand|Select|Wrap|Line Numbers
  1.  mobilePhone::com_startCom()
  2.  {
  3.  // Added for JNI interface with PTF
  4.  if(comPort == "PTF")
  5.  {
  6.  int teh_test = ptfPhone.jni_startCom();  // THIS LINE THROWS THE
  7.  ERROR!!!
  8.  return 0;
  9.  
  10.  }
  11.  

So, is 'ptfPhone' "const" or not? Is 'jni_startCom' member function
"const" or not? Read the FAQ 5.8 to understand why I am asking.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I guess the struct and the member function don't need to be "const",
that was just one way of fixing the problem I was having that was
suggested elsewhere online. I took out the "const" from all of them.

Another thing I noticed is that in the output I'm getting this at my
error...

error C2662: 'JNI_Interface: :jni_startCom' : cannot convert 'this'
pointer from 'JNI_Interface' to 'JNI_Interface &'
An object from the gc heap (member of a managed class) cannot
be converted to an non-gc reference

And I'm not sure what FAQ you are referring to.

Jul 26 '06 #6
do******@gmail. com wrote:
[..]

And I'm not sure what FAQ you are referring to.
http://www.parashift.com/c++-faq-lite/

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 26 '06 #7

<do******@gmail .comskrev i meddelandet
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
>
Victor Bazarov wrote:
>do******@gmail. com wrote:
The error is thrown on the call to jni_startCom();

Expand|Select|Wrap|Line Numbers
  1. mobilePhone::com_startCom()
Expand|Select|Wrap|Line Numbers
  1.  
  2. Does this function have a return type?
  3.  
  4.         
  5.                         
  6.                         
  7.                 {
  8. // Added for JNI interface with PTF
  9. if(comPort == "PTF")
  10. {
  11. int teh_test = ptfPhone.jni_startCom();  // THIS LINE THROWS THE
  12. ERROR!!!
  13. return 0;
  14. }
  15.  
  16.  
>>
So, is 'ptfPhone' "const" or not? Is 'jni_startCom' member
function
"const" or not? Read the FAQ 5.8 to understand why I am asking.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

I guess the struct and the member function don't need to be "const",
that was just one way of fixing the problem I was having that was
suggested elsewhere online. I took out the "const" from all of
them.

Another thing I noticed is that in the output I'm getting this at my
error...

error C2662: 'JNI_Interface: :jni_startCom' : cannot convert 'this'
pointer from 'JNI_Interface' to 'JNI_Interface &'
An object from the gc heap (member of a managed class) cannot
be converted to an non-gc reference
Are you compiling with the /clr switch set by any chance? If so, you
are using the language called C++/CLI, which is totally different.
Bo Persson
Jul 27 '06 #8

do******@gmail. com wrote:
Expand|Select|Wrap|Line Numbers
  1. JNI_Interface::jni_startCom() const
  2. {
  3.     const char* phone_class_name = "phonetest/phone/synergy/SynergyPhone";
  4. // class of phone to use
  5. ....
  6. }
  7.  
Any ideas?
You seem to have a syntax error in your code. "...." will not compile.

Jul 27 '06 #9

do******@gmail. com wrote:
[error]
error C2662: 'JNI_Interface: :jni_startCom' : cannot convert 'this'
pointer from 'JNI_Interface' to 'const JNI_Interface &'
[/error]

Normally MSVC gives that error if you try to call a non-const function
using a const object. You're doing something like the below:
struct A {
int foo() const;
int bar();
};

void func() {
const A a1;
A a2;

a2.foo(); // ok
a2.bar(); // ok
a1.foo(); // ok
a1.bar(); // error
}
K

Jul 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1983
by: Darkay Li | last post by:
I have try to create an allocator like follow: // the type of allocator must be some kind of pointer template <class Type> class PointerAllocator : public std::allocator<Type> { public: typedef std::allocator<Type> BaseClass; public: void destroy(pointer ptr)
3
2479
by: dushkin | last post by:
Hi, This is a member function I wrote: bool MyClass::operator==(const MyClass &a_suaDateTime) const { return (m_oleDateTime == a_suaDateTime.DateTime()); //m_oleDateTime an MFC class } I get this error message:
2
1600
by: darkhonor | last post by:
I'm very new to Windows development, all of my background is in Linux, so please bear with me. I am working on a class project and just for fun I'm building a frontend using VC++ 2003. The project uses the OpenSSL crypto libraries (specifically the BIGNUM functions). The offending code is: if (this->rbtnSetKeysize->Checked) { this->intKeysize = 512; // Load the Prime Number and calculate the Secret Value
1
1601
by: Bern McCarty | last post by:
I am using MEC++ in VC 7.1. I had a method on a __gc object that looked like this: __property System::UInt32 get_MyProperty(void) { System::Byte __pin * pinBytes = &m_byteArray; // entire array is now pinned NativeStruct const __nogc* nativeStructP = reinterpret_cast<NativeStruct const __nogc*>(pinBytes);
4
6243
by: nmrcarl | last post by:
I'm trying to upgrade a large project from VS 6.0 to VS 2005. After fixing a lot of things that changed (mostly sloppy coding in the original project that VS2005 didn't allow), I got the release version to build successfully. Unfortunately, it crashes right away when I start it. So now I need to build the debug version. Unfortunately, the compiler gives innumerable error messages of the sort shown below. The #include file referenced...
2
2335
by: Qasimtn | last post by:
Error occured while compiling the function which is a operator(<) function if remove the key word const in the argument no error occurs. Help me i have no idea what i have done wrong with this code....... i have mentioned the compiler error after the function implementation #include<iostream> using namespace std; // //Box Class
3
15733
by: mishink7 | last post by:
i am getting this error error C2662: 'std::vector<_Ty>::push_back' : cannot convert 'this' pointer from 'const std::vector<_Ty>' to 'std::vector<_Ty> &' with and and
3
1727
by: =?Utf-8?B?RGlwZXNoX1NoYXJtYQ==?= | last post by:
Hi all, I am porting my code in VC++ to VC.net i.e managed. I have seen somewhere that i need to convert my char* to String*, but String * doesnt perform pointer arithmetic like String* p; *p++=' '; So please suggest as to what i have to do? Am i doing wrong by converting char* to String* in managed VC.net. Thanks, Dipesh.
1
1900
TheMan1
by: TheMan1 | last post by:
Hi, I'm making a simple program in C++. I have an object named TextReader, with a function GetString(), and I also have another object, TextWriter. Now when *TextWriter is called, it needs to return a character. It will get this character from TextReader.GetString(). However, I get an error C2662 when I try to implement this. Here is my dereference operator function for TextWriter: char TextWriter::operator*() const { string tmpStr;...
0
8130
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8433
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7093
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6088
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5540
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.