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
 Implement Interface does not work for local class
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

andre.horst
Tomato Guru

Germany
150 Posts

Posted - Jun 17 2013 :  01:31:16 AM  Show Profile  Reply with Quote
Latest VAX, VC2010, Win7.

class CInterface
{
public:
	virtual void Foo() = 0 ;
} ;

void f()
{
	class CImpl : public CInter[PLACE_CURSOR_HERE]face 
	{
	public:
	} ;
}


Place cursor on CInterface and "Implement Interface" is not available in VAX pop up menu.

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Jun 17 2013 :  3:12:16 PM  Show Profile  Reply with Quote
I am seeing the same effect here. Thank you for the clear description.

case=74977

This surprised me, I was not aware you could declare a class inside a function, but thinking about it, it does make sense, since this is just another way of restricting the scope of the new class. Plus it compiles, always a good test

Do you have a lot of code that does this? Or is this only used a few times?

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

andre.horst
Tomato Guru

Germany
150 Posts

Posted - Jun 18 2013 :  12:45:26 AM  Show Profile  Reply with Quote
I use such code to create template functions that uses for example a functor class that should not be visible outside the function, thus this is a bit simplified example. So expand the real testcases with template functions and inner classes
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Jun 18 2013 :  7:09:22 PM  Show Profile  Reply with Quote
Ah, thank you for the explanation Do you have an example or two of real usage that you would be able to post, that I can use to make more realistic test cases with? I will certainly make sure to run some more complex tests on this when I get to it, its also good to know we are testing the sort of thing you are doing as well.

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

andre.horst
Tomato Guru

Germany
150 Posts

Posted - Jun 19 2013 :  02:04:10 AM  Show Profile  Reply with Quote
Sorry, most examples are to complex and have too many dependencies to other classes and the code is confidential. But here is a example that should catch most test cases (works only at VC2010SP1+). To answer your question how often I use such constructs: not very often

class __declspec( novtable ) CIInitable
{
public:
	virtual void Init( void ) = 0 ;
} ;

template< class FUNC >
typename FUNC::result_type FooBar( FUNC func, const typename FUNC::first_argument_type p )
{
	if( true == std::is_base_of< CIInitable, FUNC >::value )
	{
		func.Init() ;
	}
	return func( p, 4711 ) ;
}

template< class P >
P Foo( const P p )
{
	struct s : public std::binary_function< P, P, P >, public virtual CIInitable
	{
		result_type operator()( first_argument_type x, second_argument_type y )
		{
			return x + y ;
		}

		virtual void Init( void )
		{
			// Do some funny stuff
		}
	} ;
	s  f ;
	return FooBar( f, p ) ;
}

int result = Foo( 42 ) ;
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Jun 20 2013 :  11:36:10 AM  Show Profile  Reply with Quote
Code being confidential is normal, and expected. Thank you for this, that's definitely a more complex example than any I was likely to come up with!

Its taken a little bit of wrapping my head around. Just to make sure I understand correctly, you would be looking to trigger Implement Interface on the "struct s" created inside Foo() ?

Any reason for making this a struct? I know you can derive a struct from something else, but it is very rarely done in my experience.

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

andre.horst
Tomato Guru

Germany
150 Posts

Posted - Jun 21 2013 :  02:51:58 AM  Show Profile  Reply with Quote
In C++ class and struct are nearly the same, but in a struct you normaly have no ctor, members are public by default, different vtable, and so on. Some tricky template things can only be done with structs and not with classes (f.e. template typedefs, do not know why ). I used struct just to have a unexpected keyword for a "class" in this test-case and it seems, that I choosed right
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Jun 24 2013 :  2:02:49 PM  Show Profile  Reply with Quote
I know struct and class are virtually identical in C++, this has come up before, occasionally, when people have reported bugs deriving a struct, since it has been known to confuse our parser. Its very rare to see this done though, which is why I asked

I did not know that some things can only be done with struct's though, that's interesting, and does help to explain why you used struct here, in addition to producing a challenging test case

Thank you for the example, I have added this to the bug report, so we will know to keep an eye on code like this.

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 - Feb 26 2014 :  10:40:37 AM  Show Profile  Reply with Quote
case=74977 is fixed in build 2029
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