CINDER INITIALIZATION - visual-c++

``I am learning how to loadImage in cinder.
I used loadImage function defined in ImageIo.h file,
but When I build my code it gives the following error
c:\users\user\particle\src\particleapp.cpp(30): error C2440: 'initializing' : cannot convert from 'ParticleApp *' to 'cinder::app::AppBasic *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
How to resolve it ?

Trying to guess without seeing your code.
But have you added the parent class type to your ParticleApp class?
Where you declare
class ParticleApp { ... }
you should do:
class ParticleApp : public cinder::app::AppBasic { ... }

Related

Visual Studio warning C4596 in constructor declaration

Warning C4596 can, apparently, be solicited by several configuration. I found a few that did not match my problem so this is submited:
class dialog_base : public wxFrame
{
public:
dialog_base::dialog_base( const wxString& title );
… }
1> E:\WX\wx_numbers_01\dialog_base.h(18,28): warning C4596: '{ctor}': illegal qualified name in member declaration (compiling source file wx_numbers.cpp)
So how should this constructor be declared?
Just in case, as I read the error it comes from this part of the declaration:
dialog_base::dialog_base
I realize removing the "unexpected qualification" will resolve this warning. In your case, just use
dialog_base( const wxString& title );
May I know the reason why one would want to use
dialog_base::dialog_base( const wxString& title );

Type argument is not within its bounds Expected: Any Found: String

Given
open class BaseClass<T: Any>(...) { ... }
class MySubclass<String>(...) : BaseClass<String>(...) { ... }
I get the error
Type argument is not within its bounds
Expected: Any
Found: String
Android Studio offers me Add 'kotlin.Any' as upper bound for String which leads to
// Note the <String: Any> instead of <String>
class MySubclass<String: Any>(...) : BaseClass<String>(...)
But I don't understand why <String> isn't fine but <String: Any> is?
You need to type just
class MySubclass(...) : BaseClass<String>(...) { ... }
Where you put <String> right after MyClass, you've defined a generic type for your subclass named String. And since it has the same name as the actual class String, it's confusing. Usually a single capital letter is used for a generic type. What you wrote would be equivalent to:
class MySubclass<T>: BaseClass<T>()
Which is not allowed because your type is possibly an Any?, which wouldn't satisfy the requirement that the type extend from non-nullable Any.
<String: Any> works because it's like defining a type <T: Any>, which enables it to fit your non-nullable requirement in the base class.

Compile error when try to create singleton using shared_ptr

I try to create a singleton object using shared_ptrs. However the code does not compile when the constructors/destructor are private for the specific object
The code is below.h
//ThreadPool.h
class ThreadPool
{
public:
static std::shared_ptr<ThreadPool> & getInstance();
inline static std::shared_ptr<ThreadPool> m_threadPoolInstance;
private:
ThreadPool() =default;
~ ThreadPool() = default;
ThreadPool(ThreadPool const &) = default;
};
//ThreadPool.cpp
#include "pch.h"
#include <ThreadPool.h>
std::shared_ptr<ThreadPool> & ThreadPool::getInstance()
{
if (! m_threadPoolInstance)
{
ThreadPool * p_ThreadPool = new ThreadPool();
m_threadPoolInstance.reset(p_ThreadPool);
}
return m_threadPoolInstance;
}
I am using VS17 compiler
The error that is created is the following
error C2440: '': cannot convert from '_Ux *' to
'std::shared_ptr'
with
[
_Ux=ThreadPool
] include\memory(1462): note: No constructor could take the source type, or constructor overload resolution was ambiguous
threadpool.cpp(9): note: see reference to function template
instantiation 'void std::shared_ptr::reset(_Ux
*)' being compiled
with
[
_Ux=ThreadPool
] threadpool.cpp(9): note: see reference to function template instantiation 'void std::shared_ptr::reset(_Ux
*)' being compiled
with
[
_Ux=ThreadPool
]
When I set the constructors/destructor in public section, the compilation is succesfull.
However running the same code using gcc compiler , compiles succesfully
The conversion fails because your ThreadPool class has a private destructor.
Calling .reset(ptr) will use the delete expression (delete ptr;) as the deleter, which requires that the destructor be public.
Refer to overload (2) here: https://en.cppreference.com/w/cpp/memory/shared_ptr/reset
2-4) Replaces the managed object with an object pointed to by ptr. Y must be a complete type and implicitly convertible to T. Additionally:
2) Uses the delete expression as the deleter. A valid delete expression must be available, i.e. delete ptr must be well formed, have well-defined behavior and not throw any exceptions. Equivalent to shared_ptr(ptr).swap(*this);.
You either need to make the destructor public or provide a custom deleter.

error C3699: '^' : cannot use this indirection on type 'std::string'

I am trying to access lync from my application in this code I am getting errors.
error C3699: '^' : cannot use this indirection on type 'std::string'
error C2440: 'initializing' : cannot convert from 'System::String ^' to 'std::string *'
1> No user-defined-conversion operator available, or
1> Cannot convert a managed type to an unmanaged type
My code is as follows:
#using <Microsoft.Lync.Model.dll>
#using <Microsoft.Lync.Utilities.dll>
//namespace provided that DLL
using namespace Microsoft::Lync::Model;
//Function which is using that DLL
void getusername()
{
LyncClient ^lyncClient;
string ^text=lyncClient->Self->Contact->GetContactInformation(ContactInformationType::DisplayName)->ToString();
}
ToString() is returning a managed System::String type. This is different from the unmanaged std::string type.
To convert from one to the other, use marshal_as.

extern template DLLs and programs (crypto++)

I've been using Crypto++ with VS2005 and VS2010 for a while now. But recently I needed to use it with and application directly. The same code compiles fine when I'm compiling as a DLL and does not compile when compiling as an application.
This is the smallest sample that reproduces the error is this (based on cryptopp561\algparam.h:301 CryptoPP::AlgorithmParametersTemplate
class Base
{
protected:
virtual void MoveInto(void *p) const = 0;
};
template<class T>
class Test: public Base
{
public:
void MoveInto(void * buffer) const
{
Test<T> *x = new(buffer) Test<T>(*this);
}
};
extern template class Test<bool>;
The compilation parameters are the same, only difference that I saw was the configuration type in the project ("Application (.exe)" generates the error and "Dynamic Library (.dll)" does not).
This is the compiler error:
main.h(15): error C2061: syntax error : identifier 'buffer'
main.h(14) : while compiling class template member function 'void Test<T>::MoveInto(void *) const'
with
[
T=bool
]
main.h(20) : see reference to class template instantiation 'Test<T>' being compiled
with
[
T=bool
]
It seems to occur only when theres inheritance. Ommiting : public Base in the class Test declaration makes the error go away.
EDIT:
The problem was in a header included somewhere that defined a a debug version for operator new but didn't declared the placement new version.
Did you #include <new>, the header file that declares placement-new?
Funnily, extern templates are to tell the compiler to not instantiante at some point, so the second error does not make sense to me. Are you certain your compiler has support for extern templates? What if you do the opposite, explicit instantiation:
template class Test<bool>;

Resources