I've got quit a huge project to fix, there is a bug I can't resolve by myself:
class CEntity
{
public:
CStudioHdr * GetModelPtr();
public:
CStudioHdr * InternalGetModelPtr();
static CStudioHdr * (ThisClass::* GetModelPtr_Actual) ();
}
Here is the function to cast to:
class GenericClass {};
typedef void (GenericClass::*VoidFunc)();
inline void *GetCodeAddr(VoidFunc mfp)
{
return *(void **)&mfp;
}
The line, which doesn't let me to complie the project:
void *callback = (void *)GetCodeAddr(reinterpret_cast<VoidFunc>(&CEntity::InternalGetModelPtr));
I get this error:
error C2440: 'reinterpret_cast' : cannot convert from 'CStudioHdr *(__thiscall CEntity::* )(void)' to 'VoidFunc'
I gues it's something wrong with msvc compilers:
Visual Studio 2012 (v110)
Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012)
The remarcable moment is that there is another class:
class CAnimating : public CEntity
{
And if I move this function into this class, there are no errors.
I'm not sure if it's the best way to get a void pointer, is it correct for linux as well?
Related
I'm on first time building a project using wxWidget in Visual Studio, all config for project follow as this : https://wiki.wxwidgets.org/Microsoft_Visual_C%2B%2B_Guide
But now I have a problem when try to build this, in file any.h (from wxWidgets 3.1 include ), this error was appeared:
Error 1 error C2665: 'operator new' : none of the 4 overloads could
convert all the argument types
At block:
class wxAnyValueTypeOpsInplace
{
public:
static void DeleteValue(wxAnyValueBuffer& buf)
{
GetValue(buf).~T();
}
static void SetValue(const T& value,
wxAnyValueBuffer& buf)
{
// Use placement new
void* const place = buf.m_buffer;
::new(place) T(value); ***//Error here***
}
static const T& GetValue(const wxAnyValueBuffer& buf)
{
// Use a union to avoid undefined behaviour (and gcc -Wstrict-alias
// warnings about it) which would occur if we just casted a wxByte
// pointer to a T one.
union
{
const T* ptr;
const wxByte *buf;
} u;
u.buf = buf.m_buffer;
return *u.ptr;
}
};
I've searched for several hours but cant see anything relate to this, please help me.
More info : I'm adding wxWidgets by using NuGet, and link by static library.
This is full error message.
I didn't edit anything in wxWidgets since it has been downloaded, and i'm using Visual Studio Express 2013 for Windows Desktop.
I have a base class:
#define OUT
#define NO_VTABLE __declspec(novtable)
class NO_VTABLE Foo
{
public:
virtual bool TestSomething() const = 0;
virtual bool TestSomething(OUT unsigned int& extendedInfo) const {
UNUSED(extendedInfo);
return TestSomething();
}
};
And a derived class:
class NO_VTABLE Bar : public Foo
{
public:
virtual bool TestSomething() const {
// Do the test, return the result...
}
};
Under GCC, the program compiles cleanly with -Wall -Woverloaded-virtual. Under Visual Studio, I get a dirty compile. TestSomething from above is Available shown below.
1> ...\derived.h(78) : warning C4266: 'bool DeviceState::Available(unsigned int &) const' :
no override available for virtual member function from base 'DeviceState'; function is hidden
1> ...\base.h(794) : see declaration of 'DeviceState::Available'
1> ...\base.h(787) : see declaration of 'DeviceState'
Removing NO_VTABLE makes no difference. The warning persists.
All the TestSomething are public and virtual in both the base and derived classes, so its not clear to me what is hidden from the caller.
I'm working through testing under Visual Studio, and I've encountered it on both Visual Studio 2005, 2008 and 2010. I still have other VS's to test, but at this point, I know its not a one-off.
I prefer not to turn off the warning because the file base.h is large with lots of classes, and it might encounter other problems in the future.
What does Visual Studio claim is hidden from the caller? What is the source of the warning under Visual Studio, and how do I clear it?
If you look up error C4266 you'll find that it says A derived class did not override all overloads of a virtual function. So for this compiler you'll need to override all of the overloads for the unsigned int & variant to be visible.
I haven't looked up in the language spec to see if this is conforming or not.
Trying to compile the following call to boost::fusion::invoke in boost-1.56 fails in Visual Studio 2013 but there is no error when compiling with Visual Studio 2012.
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/fusion/functional.hpp>
void Function( int & output )
{
output = 12;
}
int main( int, char ** )
{
boost::fusion::vector1< int > parameters;
boost::function< void( int & ) > function = &Function;
boost::fusion::invoke( function, parameters );
return 0;
}
The compiler output is:
boost\fusion\functional\invocation\invoke.hpp(205): error C2039: 'type' : is not a member of 'boost::result_of<Function (const int &)>'
with
[
Function=boost::function<void (int &)>
]
boost\fusion\functional\invocation\invoke.hpp(163) : see reference to class template instantiation 'boost::fusion::detail::invoke_impl<boost::function<void (int &)>,Sequence,1,false,true>' being compiled
with
[
Sequence=const boost::fusion::vector1<int>
]
main.cpp(16) : see reference to class template instantiation 'boost::fusion::result_of::invoke<boost::function<void (int &)>,const boost::fusion::vector1<int>>' being compiled
It's failing when trying to instantiate boost::result_of with a const Sequence. I've looked in boost\fusion\functional\invocation\invoke.hpp and there are two overloads of boost::fusion::invoke, one is const and the other is non-const.
I think that the Visual Studio 2013 compiler is attempting to instantiate the const version even though that is not the one that should be called. If I comment out the const version in invoke.hpp the example compiles fine.
Is this a bug with Visual Studio 2013 or boost-1.56?
Is there any workaround for this problem without modifying the boost sources?
I suspect the default for BOOST_RESULT_OF has changed for VS2013.
#define BOOST_RESULT_OF_USE_TR1
makes it compile. Chances are this bug is known and has been fixed in trunk, but you might want to report it still
I have such code:
#include <functional>
struct Foo {
template<typename T>
static void f(int);
};
template<>
void Foo::f<int>(int) {}
int main()
{
std::function<void(int)> func;
//func = static_cast<void (*)(int)>(Foo::f<int>);/works
func = Foo::f<int>;//compilation failure
return 0;
}
VS 2012 and 2013 Preview give compile time error at line:
func = Foo::f<int>;//compilation failure
error C3867: Foo::f: in function call no argument list, use "&Foo::f" to create pointer to member
error C2440: =: can not convert "overloaded-function" into "std::function"
But gcc 4.8.1, clang 3.3 and Intel Compiler 13.1.3 compile
this code with options (-Wall -pedantic -std=c++11) without
any warnings and errors.
So is this compiler bug of C++ compiler of Visual Studio?
Yes, it is a bug, visual studio 2013 rc compiles this without a problem so it looks like they have fixed it.
I installed visual c++ November 2012 CTP but it seems i do something wrong because i still can't use delegating constructors
I set the Platform Toolset to : Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012)
This is my code:
#pragma once
#include<string>
class Hero
{
private:
long id;
std::string name;
int level;
static long currentId;
Hero(const Hero &hero); //disable copy constructor
Hero& operator =(const Hero &hero); //disable assign operator
public:
Hero();
Hero(std::string name, int level);
long GetId() const { return this->id; }
std::string GetName() const { return this->name; }
int GetLevel() const { return this->level; }
void SetName(std::string name);
void SetLevel(int level);
};
PS: Any tips regarding to c++11 and visual studio 2012 are more then welcomed. Thanks.
LE: This is the implementation file:
#include"Hero.h"
long Hero::currentId = 0;
Hero::Hero(std::string name, int level):name(name), level(level), id(++currentId)
{
}
Hero::Hero():Hero("", 0)
{
}
void Hero::SetName(const std::string &name)
{
this->name = name;
}
void Hero::SetLevel(const int &level)
{
this->level = level;
}
I get the following error message on the parameterless constructor:
"Hero" is not a nonstatic data member or base class of class "Hero"
The error message you quote is being reported by IntelliSense, which does not yet support the new C++11 language features. Note that the full text of the error message reads (emphasis mine):
IntelliSense: "Hero" is not a nonstatic data member or base class of class "Hero"
The announcement for the November CTP states (emphasis mine):
While a new Platform Toolset is provided for convenience of integrating the compiler as part of the Visual Studio 2012 build environment, the VS 2012 IDE, Intellisense, debugger, static analysis, and other tools remain essentially unchanged and do not yet provide support for these new C++11 features.
The compiler, which is updated by the November CTP, rejects the code with the following errors:
error C2511: 'void Hero::SetName(const std::string &)' : overloaded member function not found in 'Hero'
c:\jm\scratch\test.cpp(6) : see declaration of 'Hero'
error C2511: 'void Hero::SetLevel(const int &)' : overloaded member function not found in 'Hero'
c:\jm\scratch\test.cpp(6) : see declaration of 'Hero'
These errors are expected because your code is ill-formed (the parameters of SetLevel and SetName are passed by value in their inline declarations, and by reference in their definitions). When these errors are fixed, the compiler accepts your code.