Now I'm geting an error:
1>c:\development\document_manager\document_manager\storage_manager.h(7) : error C2079: 'storage_manager::db' uses undefined struct 'sqlite3'
with
#pragma once
#include "sqlite3.h"
class storage_manager
{
sqlite3 db;
sqlite3** db_pp;
public:
void open()
{
sqlite3_open("data.db", db_pp);
}
};
Old Question:
Hi everyone. I downloaded sqlite-amalgamation-3_6_13.zip from http://www.sqlite.org/download.html, but I'm not able to compile it in my project. I receive many errors like:
c:\pathtoproject\sqlite3.c(11337) : error C2440: '=' : cannot convert from 'void *' to 'char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
c:\pathtoproject\sqlite3.c(12023) : error C2440: '=' : cannot convert from 'void *' to 'sqlite3_int64 *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
What do I need to do to compile my project properly? Thanks!
Edit:
I don't want to compile the whole program as C, I just want to compile three files as c, is this possible?
EDIT: FIXED! I created an new project.
It looks like you might be trying to compile a C program using a C++ compiler. While there is a lot of C code which is also valid C++, they are different languages.
Your compiler may have some switch or setting to compile C code. Check your compiler documentation.
You need to compile the file as C code rather than C++.
Right click on either the project or just the .c file, and in properties, make sure it is set to compile as C, rather than C++. (You may want to set this setting just for the file, not the entire project)
Doesn't the compiler tell you what to do? You need an explicit cast:
void *pv = /* some value */;
char *pc = (char*) pv;
This is of course not a problem in C, but an issue of C++.
Related
i have Microsoft Visual Studio (MSVS) 2012 Pro and i have set warning level to a slightly elevated level of 4. when doing this i am getting warnings for some of the included header files from the boost library. the message is this:
C:\Users\****\boost/optional/optional.hpp(595): warning C4244: 'initializing' : conversion from 'T_DOUBLE' to 'float', possible loss of data
C:\Users\****\boost/optional/optional.hpp(430) : see reference to function template instantiation 'void boost::optional_detail::optional_base<T>::construct<double>(Expr &&,const void *)' being compiled
with
[
T=T_FLOAT,
Expr=T_DOUBLE
]
C:\Users\****\boost/optional/optional.hpp(430) : see reference to function template instantiation 'void boost::optional_detail::optional_base<T>::construct<double>(Expr &&,const void *)' being compiled
with
[
T=T_FLOAT,
Expr=T_DOUBLE
]
the code in the file leading to this warning is this (line 610 on most recent beta of boost 1.64.0.B2 still resembles it exactly - but i am not on the beta now):
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
// Constructs using any expression implicitly convertible to the single argument
// of a one-argument T constructor.
// Converting constructions of optional<T> from optional<U> uses this function with
// 'Expr' being of type 'U' and relying on a converting constructor of T from U.
template<class Expr>
void construct ( Expr&& expr, void const* )
{
new (m_storage.address()) value_type(boost::forward<Expr>(expr)) ;
m_initialized = true ;
}
what is the reason (=learn to understand) for this warning and how to eliminate it in the boost header for me any anyone else? alternatively thinking: does it make sense to "fix" it in such a global way, or is there a deeper meaning pointing rather to somewhere else (either boost or application codes) to improve or fix those other codes?
You are probably passing a double literal into method that expects float. Something like foo(1.0) instead of foo(1.0f)
trying to compile the TinyXml++ tutorial with CodeBlocks (16.01) and with VS2013 I get the same error at following line:
ticpp::Element* pElem = doc.FirstChildElement()->NextSibling();
CodeBlocks error:
invalid conversion from 'ticpp::Node*' to 'ticpp::Element*'
[-fpermissive]
VS2013 error:
cannot convert from 'ticpp::Node *' to 'ticpp::Element *'
Any idea?
In case you still want to compile it, regardless of whether there is an error in the tutorial, you can use the auto keyword for variable declaration.
For example:
auto pElem = doc.FirstChildElement()->NextSibling();
This way, the compiler will deduce the variable type at compile time.
The return type of NextSibling() is Node*. If you want Element* as return type, you can use NextSiblingElement() instead.
I'm beginner. I'm using VS2008. In file1.cpp I'm calling the OALPAtoVA function present in file2.c. I'm getting C2440. I believe it is due to some confusion caused between C & C++ files during compilation.
file1.cpp
extern OMAP_MMCHS_REGS *m_pbRegisters;
m_pbRegisters = OALPAtoUA(AM33X_MMCHS1_REGS_PA); //error at this line
file_2.c
VOID* OALPAtoVA(UINT32 pa, BOOL cached)
{
//some code
return va;
}
The error I get is,
error C2440: '=' : cannot convert from 'void *' to 'OMAP_MMCHS_REGS *'
How to resolve this error?
Assuming the difference between OALPAtoUA and OALPAtoVA is just a typo in your question.
The problem is that unlike C, C++ doesn't provide an implicit conversion from void* to a different pointer type. So if your function returns a void*, you have to cast it explicitly:
m_pbRegisters = static_cast<OMAP_MMCHS_REGS*>(OALPAtoVA(AM33X_MMCHS1_REGS_PA));
I'm using Visual Studio 2008 Express Edition to compile the following code in a header file:
bool is_active(widget *w);
widget is defined earlier as,
typedef void widget;
The compiler complains with the error:
>c:\projects\engine\engine\engine.h(451) : error C2061: syntax error : identifier 'is_active'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : ';'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : 'type'
I get similar errors for all other functions returning bool.
NB. The following compiles fine:
void widget_activate_msg(widget *g, message *msg);
Why would this give a compiler error?
Some people have requested I post the code - here it is:
Line 449: widget * widget_new_from_resource(int resource_id);
Line 450: void widget_delete_one(widget *w);
Line 451: bool is_active(widget *w);
EDIT - this is now fixed:
#BatchyX commented below about whether I was using C or C++. What I didn't know was that Visual C++ 2008 will compile any file by default (but you can override this setting ) with the .c extension as C and those with .cpp as C++. ( the error was caused when compiling a .c file including "Engine.h" ).
Most likely, something above this line has a syntax error. Did you forget }s or ; after a class declaration ?
Also make sure you are using C++ and not C. C doesn't have a bool type. If you're using C, then use an int instead.
I'm guessing that it's not possible to typedef void. Why not use typdef void* WidgetPtr; and then bool is_active(WidgetPtr w);
EDIT: Having done some tests it's clear that void can be typedef'd and it can be part of the function signature as shown in the users code. So the only other solution is that whichever header has declared typedef void Widget is not included within the file that declares/defines the function or you're having a #def guard statement clash.
I am getting the following error while migrating VC6 code to VS2008. This code works fine in VC6 but gives a compilation error in VC9. I know it is because of a compiler breaking change. What is the problem and how do I fix it?
error C2440: 'initializing' : cannot convert
from 'std::_Vector_iterator<_Ty,_Alloc>'
to 'STRUCT_MUX_NOTIFICATION *'
Code
MUX_NOTIFICATION_VECTOR::iterator MuxNotfnIterator;
for(
MuxNotfnIterator = m_MuxNotfnCache.m_MuxNotificationVector.begin();
MuxNotfnIterator != m_MuxNotfnCache.m_MuxNotificationVector.end();
MuxNotfnIterator ++
)
{
STRUCT_MUX_NOTIFICATION *pstMuxNotfn = MuxNotfnIterator; //Error 2440
}
If it worked before, I am guessing MUX_NOTIFICATION_VECTOR is a typedef
typedef std::vector<STRUCT_MUX_NOTIFICATION> MUX_NOTIFICATION_VECTOR;
The iterator for a container can often be mistaken with a pointer (because it works the same way) and, in the case of some stl implementations, it can actually be a pointer (it probably was the case with STL provided with VC6). But there is no guarantee about that.
What you should do is the following :
STRUCT_MUX_NOTIFICATION& reference = *MuxNotfnIterator;
// or
STRUCT_MUX_NOTIFICATION* pointer = &(*MuxNotfnIterator);
I think this should do the trick:
STRUCT_MUX_NOTIFICATION *pstMuxNotfn = &(*MuxNotfnIterator);
You'll need to dereference the iterator to get the appropriate struct (not sure why it worked before?):
STRUCT_MUX_NOTIFICATION *pstMuxNotfn = *MuxNotfnIterator;