g++

Why does this code compile with g++ but not gcc?

别来无恙 提交于 2019-12-13 04:25:48
问题 The following piece of code compiles with g++ and not gcc, and am stuck wondering why? inline unsigned FloatFlip(unsigned f) { unsigned mask = -int(f >> 31) | 0x80000000; return f ^ mask; } I would assume that in C++, int(f >> 31) is a constructor but that leaves me wondering why it's included in the code. Is it necessary? 回答1: C doesn't support the C++ "function-style" casting. You need to write it like this unsigned mask = -(int)(f >> 31) | 0x80000000; See cast operator 回答2: You can use C

How to detect whether there is a specific member variable in class?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 04:09:24
问题 For creating algorithm template function I need to know whether x or X (and y or Y) in class that is template argument. It may by useful when using my function for MFC CPoint class or GDI+ PointF class or some others. All of them use different x in them. My solution could be reduces to the following code: template<int> struct TT {typedef int type;}; template<class P> bool Check_x(P p, typename TT<sizeof(&P::x)>::type b = 0) { return true; } template<class P> bool Check_x(P p, typename TT

Relocation R_X86_64_PC32 against undefined symbol can not be used when making a shared object; recompile with -fPIC

那年仲夏 提交于 2019-12-13 03:19:15
问题 I recently upgraded gSOAP from 2.8.7 to 2.8.76. I had to make a few minor code adjustments for the upgrade, but after the upgrade the code won't link on the computer it would before. I'm trying to use gSOAP to create a shared library on a computer which uses g++ 4.9.2. I've condensed the code down to create a test case that simplifies things a bit to try to identify where the failure is occurring. gSOAP generates some ebaySoapLib* files when I run: /usr/local/bin/soapcpp2 -z1 -C -w -x -n

'Scanner' does not name a type error in g++

亡梦爱人 提交于 2019-12-13 01:28:16
问题 I'm trying to compile code in g++ and I get the following errors: In file included from scanner.hpp:8, from scanner.cpp:5: parser.hpp:14: error: ‘Scanner’ does not name a type parser.hpp:15: error: ‘Token’ does not name a type Here's my g++ command: g++ parser.cpp scanner.cpp -Wall Here's parser.hpp: #ifndef PARSER_HPP #define PARSER_HPP #include <string> #include <map> #include "scanner.hpp" using std::string; class Parser { // Member Variables private: Scanner lex; // Lexical analyzer Token

Linker and dependencies

喜你入骨 提交于 2019-12-13 00:38:38
问题 For a Linux/g++ project, I have a helper library ("libcommon.a") that I wrote that is used in two different programs ("client" and "server"). One particular source file among several, oshelper.cpp, has a set of unrelated utility functions: // header file #ifndef OSHELPER_H #define OSHELPER_H size_t GetConsoleWidth(); uint32_t GetMillisecondCounter(); #endif // ----------------------------------------- // Code file #include "commonincludes.h" #include "oshelper.h" size_t GetConsoleWidth() {

Compiling JNI C++ Native Code with x86_64-w64-mingw32-g++

时光总嘲笑我的痴心妄想 提交于 2019-12-13 00:27:20
问题 I want to compile and run a simple Hello World program that declares and calls a native print method (defined in C++) from Java. HelloCPP.java class HelloCPP{ private native void print(); public static void main(String [] args){ new HelloCPP().print(); } static{ System.loadLibrary("HelloCPP"); } } HelloCPP.cpp #include <jni.h> #include<iostream> #include "HelloCPP.h" using namespace std; extern "C" JNIEXPORT void JNICALL Java_HelloCPP_print(JNIEnv *env, jobject obj){ cout << "Hello World from

Pointer to array of unknown bound? [duplicate]

大憨熊 提交于 2019-12-12 21:28:43
问题 This question already has answers here : Why is function(char * array[]) a valid function definition but not (char (*array)[] in C? (4 answers) Closed 5 years ago . The following function declaration is accepted by gcc, but not accepted by g++. void do_something(char (*)[]); The error given by g++ is: error: parameter '<anonymous>' includes pointer to array of unknown bound 'char []' I believe that in C, the parameter is converted to char** which is why gcc accepts it fine. Can I make g++

Static lib loading related issue

你离开我真会死。 提交于 2019-12-12 20:15:57
问题 Suppose I want to version the libs in binaries made. For static libs, I thought this approach would work but it does not: LibInfo.h - Base class for all libinfo classes. Registers an object in gvLibInfo vector when a child is constructed. #ifndef IFACE_H #define IFACE_H #include <vector> class LibInfo; extern std::vector<LibInfo*> gvLibInfo; class LibInfo { public: virtual int getversion() = 0; void reglib() { gvLibInfo.push_back(this); } LibInfo() { reglib(); } virtual ~LibInfo() {} };

Building Qt project for C++11 standard

↘锁芯ラ 提交于 2019-12-12 20:13:54
问题 I am trying to build my Qt project with C++11 standard. I added this flag in the build steps, additional argument option, in the Qt Creator : -std=c++11 But I got this error while building : Unknown option -std=c++11 g++ version info : g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Any ideas ? 回答1: Use the qmake project file, add this line: QMAKE_CXXFLAGS += -std=c++11 LE: also 4.6.3 might not support C++11 (as far as i know 4.7 and higher support -std=c++11) so the option for the 0x features

Gcc check whether the given class has operator+

◇◆丶佛笑我妖孽 提交于 2019-12-12 20:06:48
问题 I created a code below to test whether there is an operator+ overload for 2 classes: template<typename T, typename U> struct _has_plus_hlp { template<typename X, typename Y> static std::true_type _check(X&, Y&, decltype(std::declval<X>() + std::declval<Y>()) = {}); static std::false_type _check(...); using type = decltype(_check(std::declval<T>(), std::declval<U>())); }; template<typename X, typename Y> constexpr bool has_plus_v = _has_plus_hlp<X, Y>::type::value; int main() { std::cout <<