Apparently, MSVC2005 fails to inline local classes' member functions which leads to LNK2005.
I'm facing this LNK2005 error when compiling the following:
common.h content:
inline void wait_what()
{
struct wtf
{
void ffffuuu() {}
} local;
}
foo.cpp content:
#include "common.h"
void foo()
{
wait_what();
}
bar.cpp conte...
I am trying to do the following: Obtain the address of a member function from a class that was locally defined within a function.
class ConnectionBase
{
};
template class<EventType, SinkType>
class ConnectionImpl : public ConnectionBase
{
public:
typedef void (SinkType::*EventCallback)(EventType const&);
};
template<class EventType>
...
void foo() {
struct Foo { .. };
std::vector<Foo> vec; // why is this illegal?
}
I'm not returning Foo to the outside world. It's just a temporary type that I use within the function.
...
hi
I would like to know if the following is allowed:
template < class C >
void function(C&);
void function() {
class {} local;
function(local);
}
thanks
...
GCC doesn't seem to approve of instanciating templates with local classes:
template <typename T>
void f(T);
void g()
{
struct s {};
f(s()); // error: no matching function for call to 'f(g()::s)'
}
VC doesn't complain.
How should it be done?
...
I am reading "Local Classes" concept in Object-oriented programming with C++ By Balagurusamy (http://highered.mcgraw-hill.com/sites/0070593620/information_center_view0/).
The last line says "Enclosing function cannot access the private members of a local class. However, we can achieve this by declaring the enclosing function as a friend...
void foobar(){
int local;
static int value;
class access{
void foo(){
local = 5; /* <-- Error here */
value = 10;
}
}bar;
}
void main(){
foobar();
}
Why doesn't access to local inside foo() compile? OTOH I can easily access and modify the static variable v...