Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Unrecognized "this" pointer with using namespace

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
diarrhio Posted - Jan 11 2011 : 1:18:15 PM
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.
4   L A T E S T    R E P L I E S    (Newest First)
sean Posted - Feb 02 2016 : 7:52:53 PM
case=4135 is fixed in build 2089.
accord Posted - Jan 12 2011 : 4:03:11 PM
I am seeing the same effect here. Thank you for the sample code:

case=4135

I've change the title for you :)
diarrhio Posted - Jan 12 2011 : 12:05:34 PM
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 { ... }"
accord Posted - Jan 11 2011 : 9:01:49 PM
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);
}



© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000