Error in TinyXml++ tutorial - c++

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.

Related

C++ how to cast return value from sscanf

today I would like to know if there is a way to cast the return value which I got from sscanf. The idea is that I am currently using the following code:
sscanf(reinterpret_cast<char *>(randomString), "%x", &hMonLongExam)
where
hMonLongExam
My question is if there is a possible way to get rid of
warning C4477: 'sscanf' : format string '%x' requires an argument of type 'unsigned int *', but variadic argument 1 has type 'HMONITOR *'
without using #pragma ignore of course.
Thanks a lot

error: cannot convert 'std::basic_string<char>::iterator ...' to 'const char* for argument '1' ...'

I'm getting the following error:
error: cannot convert 'std::basic_string<char>::iterator {aka __gnu_cxx::__normal
_iterator<char*, std::basic_string<char> >}' to 'const char*' for argument '1'
to 'int remove(const char*)'
For some reason, my program compiles perfectly when I'm working on a Mac... but once I use a Linux machine, this error pops up in more than one place.
Here's one of the instances where the error pops up:
SomeClass::SomeClass(string t, string art, Time dur) {
char chars[] = ",";
t.erase(std::remove(t.begin(), t.end(), chars[0]), t.end());
art.erase(std::remove(art.begin(), art.end(), chars[0]), art.end());
// Some more code ...
}
More specifically, the error is coming from this line:
t.erase(std::remove(t.begin(), t.end(), chars[0]), t.end());
Does anyone know how to approach this problem?
You forgot to #include <algorithm>, where std::remove is located. Without that, your compiler only knows about this std::remove (I get the same error with Visual C++ 14), which is defined in indirectly included <cstdio> header.
Different behavior among compilers is a result of different #include hierarchies of the standard library implementations.

GCC allowing implicit int to pointer conversion?

So I mistakenly passed an int into a function parameter expecting a pointer to a const object and I got this warning from GCC:
jni/../../../Source/Controller/UserExperienceManager.cpp: In member function 'void CUserExperienceManager::SendUXPToPOS(Types::CString)':
jni/../../../Source/Controller/UserExperienceManager.cpp:243:78: warning: invalid conversion from 'int' to 'const WebService_POSAgent::CDataCheck*' [-fpermissive]
jni/../../../../../Core/WebServices/Services/POSAgent/POSAgent.h:80:18: warning: initializing argument 2 of 'CEvent& WebService_POSAgent::CPOSAgent::AddUserExperienceID(Types::CString, const WebService_POSAgent::CDataCheck*, Types::CString)' [-fpermissive]
I tried to create a reproducible sample of this but I wasn't able to and I can't share too much of the code here. I compiled the same thing on MSVC9 and it properly gave me an error. I'm just in shock that I'm not getting an error from GCC on this! Anyone know why? Here are some simple snippets:
Function Declaration (class member function):
CEvent& AddUserExperienceID(CString userExperienceId, CDataCheck const* check, CString requestId = REQUEST_ID);
Function Call Site:
int nCheckNum = /*some value*/;
CPOSAgent::Instance().AddUserExperienceID(m_UserExperienceId, nCheckNum);
You're compiling that code with -fpermissive set which is downgrading the error to a warning.
-fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings.
Thus, using -fpermissive will allow some nonconforming code to compile.
What does the fpermissive flag do?

error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'type *'

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;

SQLite3 object not understood?

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++.