Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Unrecognized "this" pointer with using namespace
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

diarrhio
Ketchup Master

53 Posts

Posted - Jan 11 2011 :  1:18:15 PM  Show Profile  Reply with Quote
Consider the following code:
void SomeFunctionCallback(void * clientData);

SomeClass::SomeMethod()
{
  int id = MEventMessage::addEventCallback("PreFileNewOrOpened", SomeFunctionCallback, this);
}

The "this" pointer will be underlined red. However, if you add an empty set of parentheses to the callback parameter, this will be recognized. The lack of parentheses is causing VAX to get confused.

Not a huge deal, just something I noticed.

Edited by - accord on Jan 12 2011 4:02:45 PM

accord
Whole Tomato Software

United Kingdom
3279 Posts

Posted - Jan 11 2011 :  9:01:49 PM  Show Profile  Reply with Quote
I created a dummy class for SomeClass and "this" wasn't underlined anymore. So I decided to extend the snippet to a compilable form but I still don't see any underline.
What am I doing differently?
What Visual Assist and Visual Studio versions are you using?
I moved SomeFunctionCallback to a class, because the last parameter of MEventMessage::addEventCallback suggests that SomeFunctionCallback is in a class:

class SomeBaseClass
{

};

typedef void (SomeBaseClass::*METHODPTR)(void*);


class SomeClass : public SomeBaseClass
{
public:
	void SomeMethod();
	void SomeFunctionCallback(void * clientData) {}
};

class MEventMessage
{
public:
	static int addEventCallback(char* str, METHODPTR method, SomeBaseClass* obj) {return 0;}
};

void SomeClass::SomeMethod()
{
	int id = MEventMessage::addEventCallback("PreFileNewOrOpened", (METHODPTR)&SomeClass::SomeFunctionCallback, this);
}


Go to Top of Page

diarrhio
Ketchup Master

53 Posts

Posted - Jan 12 2011 :  12:05:34 PM  Show Profile  Reply with Quote
The "this" parameter is passed in to be the value of the "clientData" parameter which gets passed into the callback, so it is not a class method, but a global function.

Regardless, I did some more digging. It appears that the problem is related to how you use namespaces and has nothing to do with function pointers (too bad I can't change the title of the post).

Our class is wrapped in a namespace. However, in the .cpp file, we don't enclose the whole class in a namespace but instead do a "using namespace OurNameSpace;". If I completely get rid of the namespace, or change it such that we wrap the .cpp implementation in the namespace (rather than relying on a "using" statement up top), the "this" pointer gets recognized.

Here is the minimal code to reproduce the problem:

// In SomeClass.h

#pragma once

namespace SomeNamespace
{
	class SomeClass
	{
	public:
		SomeClass();
	};
}

// In SomeClass.cpp

#include "./SomeClass.h"

using namespace SomeNamespace;

SomeClass::SomeClass()
{
  SomeClass * ptr = this;
}


To get rid of the problem, get rid of the "using namespace SomeNamespace;" line and surround the constructor with "namespace SomeNameSpace { ... }"
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3279 Posts

Posted - Jan 12 2011 :  4:03:11 PM  Show Profile  Reply with Quote
I am seeing the same effect here. Thank you for the sample code:

case=4135

I've change the title for you :)
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Feb 02 2016 :  7:52:53 PM  Show Profile  Reply with Quote
case=4135 is fixed in build 2089.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2021 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000