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
 Problems with namespaces (C++)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

frham20
Starting Member

Canada
1 Posts

Posted - Nov 09 2011 :  12:05:41 PM  Show Profile  Reply with Quote
It seems Visual Assist is having a hard time with namespaces and typedef-ed templated classes.

We're working on a projet for which there are a lot of namespaces and many class names are re-used inside different namespaces.
For example we might have this case:

namespace A { namespace B { class MyClass{}; }}
namespace A { namespace C { class MyClass{}; }}

when working in the the .cpp file of A::C::MyClass, while trying to list the members of A::B::MyClass because it is used inside the other one, Visual Assist seems to fail most of the time. It lists the members of A::C::MyClass.

We have typedefs for a templated RefCount-ing class and we name everything this way:

typedef RefCount<MyClass> MyClassPtr;

then we use MyClassPtr everywhere instead of the explicit template. Makes for much more readable code but again Visual Assist seems to get confused by this and won't list the proper methods far too often.

Are those known issues? Any known work-around?

Visual Assist is really precious for us but since we've been using a lot of templates and typedef-ed templated classes we ended up losing much of its functionnalities.

Edited by - frham20 on Nov 09 2011 12:06:39 PM

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 10 2011 :  2:44:55 PM  Show Profile  Reply with Quote
I have constructed a test code based on your description, but wasn't able to reproduce your problem so far. I use the following test code. You may be using a different code structure that is the cause of the problem.

template <class T> class RefCount
{
public:
	T* Ptr;
	T* operator->()
	{
		return nullptr;
	}
};

namespace A { namespace B { class MyClass{public: int Apple;}; }}
namespace A { namespace C { class MyClass{public: int Orange;}; }}

typedef RefCount<A::B::MyClass> MyClassPtr; 

void func()
{
	MyClassPtr ptr;
	ptr->Apple;
}


I got the correct listbox after I have typed "ptr->" in function "func".
Can you please test the sample on your side? If it is working than are you seeing the difference between this code and your "real" code that may be causing this problem for you?
I know, this is an extremely oversimplified example, but usually I can reproduce problems with simple test codes like this when I found the "trigger" that is the cause of the problem.

Edited by - accord on Nov 10 2011 2:47:06 PM
Go to Top of Page

dspdeveloper
Junior Member

10 Posts

Posted - Nov 16 2011 :  11:59:13 AM  Show Profile  Reply with Quote
I have a very similar problem, with static member functions (maybe this info is helpful , maybe not ;)
Look at the getInstance() Method



template <class T> class RefCount
{
public:
	T* Ptr;
	T* operator->()
	{
		return nullptr;
	}

	static T* getInstance()
	{
		return nullptr;
	}
};


namespace A { namespace B { class MyClass{public: int Apple;}; }}

typedef RefCount<A::B::MyClass> MyClassPtr; 

void func()
{
	MyClassPtr::getInstance()->Apple;
	MyClassPtr ptr;
	ptr->Apple;
}

Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 16 2011 :  6:21:10 PM  Show Profile  Reply with Quote
What problem are you exactly seeing? For me, all instances of Apple are recognized and get the correct listboxes and definition fields using VA1859 and VS2010 SP1, as you can see on the screenshot. I also get the correct definition info for getInstance(). Are you seeing a different effect on your side? (When definition field is correct it means that VA is aware of the symbol and normally, other features should also work.)
What VA and IDE version are you using?
If you get different results, can you please try creating a clear new test project to see if it makes any difference?


Edited by - accord on Nov 16 2011 6:28:02 PM
Go to Top of Page

dspdeveloper
Junior Member

10 Posts

Posted - Nov 17 2011 :  06:39:12 AM  Show Profile  Reply with Quote
Sorry, i have to modify the demo to demonstrate the issue in new empty project, you need 3 files:

> File "h3.h"


#define BEGIN_MY_NAMESPACE namespace myNAMESPACE {
#define END_MY_NAMESPACE } 


> File "h2.h"


#include "h3.h"

BEGIN_MY_NAMESPACE

template <class T> class RefCount
{
public:
	T* Ptr;
	T* operator->()
	{
		return 0;
	}

	static T* getInstance()
	{
		return 0;
	}
};

END_MY_NAMESPACE


> File "testVAX.cpp"


#include "h2.h"

namespace myNAMESPACE
{
	namespace A { namespace B { class MyClass{public: int Apple;}; }};

	typedef RefCount<A::B::MyClass> MyClassPtr; 


	void func()
	{
		MyClassPtr::getInstance()->Apple;
		MyClassPtr ptr;
		ptr->Apple;
	}
}



Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 18 2011 :  6:56:22 PM  Show Profile  Reply with Quote
*ah* Thank you for the elaboration, now I am seeing the same problem, which is caused by the namespace via macro approach which is a know problem, unfortunately:

case=60804

The only "workaround" I am aware of is to define the namespace directly:
namespace myNAMESPACE {
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 18 2011 :  9:34:12 PM  Show Profile  Reply with Quote
Nope, it seems I was wrong. I've been fiddling around with the source and the problem is based on the order of the source files. The most interesting part is that when I used your original description, I wasn't able to reproduce the problem. But I was in several little bit different circumstances.

Can you please try rebuilding your symbol database using your little sample project? It should help. VA might got confused when you tried to reproduce the problem?
In case it isn't: can you please try moving the content of h3.h to the beginning of h2.h? It also has helped for me. If everything is parsed in the correct order it seemed to work for me.
I've found an other problem as well, but not yet sure if it's connected, I will decide how to proceed based on your reply.

Edited by - accord on Nov 18 2011 9:35:04 PM
Go to Top of Page

dspdeveloper
Junior Member

10 Posts

Posted - Nov 21 2011 :  05:07:20 AM  Show Profile  Reply with Quote
the namespace/makro structure is used by a third party class library i use, and i have the problem in all current projects, to change it definitely not a solution here :(
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 21 2011 :  9:30:48 PM  Show Profile  Reply with Quote
My point was that I wasn't able to reproduce the problem, so my post about the macro might not apply. However, I was able to create situation when VA failed, I have put in a bug report for that:

case=62858

But generally, I wasn't able to reproduce the problem with your exact steps so I might have reproduced a different problem. This is why I asked whether you where able to reproduce the problem yourself in a test project and whether a rebuild helps or not. Just for clarification

Basically it seems that the problem appears when the files are parsed in a specific order.
Go to Top of Page

dspdeveloper
Junior Member

10 Posts

Posted - Dec 20 2011 :  09:24:06 AM  Show Profile  Reply with Quote
The bug is still present, with the steps i described i'm able to reproduce the problem. The bug appears here and there. I recently renewed my license in order to remove the problems :(
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Dec 20 2011 :  11:44:01 AM  Show Profile  Reply with Quote
Unfortunately this has not yet been fixed. This bug is still in our list of things to look at. This thread should be updated when this is fixed.

zen is the art of being at one with the two'ness
Go to Top of Page

dspdeveloper
Junior Member

10 Posts

Posted - Apr 03 2012 :  07:03:16 AM  Show Profile  Reply with Quote
FYI, build 1901, still not fixed :(
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Apr 03 2012 :  7:36:29 PM  Show Profile  Reply with Quote
Looking over this thread, I have created a sample project in VS2010, using your description, and I cannot reproduce the problem, using VA 1901. I have uploaded my sample project here:

http://forum.wholetomato.com/colin/forumimages/cpp_namespaces_topic_10434.zip

can you please download and open this VS2010 solution on your system. In the file "testVAX.cpp", I am testing Find References on "Apple" on line 16, and getting 3 results.

What result do you get? It would be useful to work out why we cannot reproduce the exact problem you are seeing so far.

zen is the art of being at one with the two'ness
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Nov 07 2014 :  09:54:23 AM  Show Profile  Reply with Quote
case=62858 is fixed in build 2052
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000