g++

Undefined symbols for architecture i386:

我的梦境 提交于 2019-12-18 08:26:20
问题 I've recently moved over to a mac, and am struggling using the command line compilers. I'm using g++ to compile, and this builds a single source file fine. if I try to add a custom header file, when I try to compile using g++ I get undefined symbols for architecture i386. The programs compile fine in xCode however. Am I missing something obvious? tried using g++ -m32 main.cpp... didn't know what else to try. Okay, The old code compiled... Have narrowed it down to my constructors. class Matrix

Confusion in regards to purpose/behavior of -Waggregate-return?

夙愿已清 提交于 2019-12-18 07:52:06
问题 While looking at the GCC's warning options, I came across -Waggregate-return . -Waggregate-return Warn if any functions that return structures or unions are defined or called. (In languages where you can return an array, this also elicits a warning.) small example that elicits the warning: class foo{}; foo f(void){return foo{};} int main(){} $ g++ -std=c++0x -Waggregate-return -o main main.cpp main.cpp: In function ‘foo f()’: main.cpp:2:5: warning: function returns an aggregate [-Waggregate

std::future exception on gcc experimental implementation of C++0x

孤街醉人 提交于 2019-12-18 07:37:39
问题 I'm experimenting with C++0x threading, partially implemented in gcc 4.5 and I've got a problem, which I can't understand. Let's have a look on this code #include <future> #include <iostream> int main() { std::cout << std::async([]() { return 10; }).get() << std::endl; } it's quite simple and should work, but it's not. It throws std::system_error terminate called after throwing an instance of 'std::system_error' what(): Aborted what() returns empty string, so there is no error information at

Using a class function in int main()

試著忘記壹切 提交于 2019-12-18 07:25:33
问题 I am having problems calling my functions from my main program. These functions HAVE to be in my class. How do I access them from my int main()? #include <iostream> #include <stdio.h> #include <pthread.h> #include <stdlib.h> #include <math.h> #include <sys/types.h> #include <semaphore.h> #include <synch.h> using namespace std; class myCountingSemaphoreUsingBinarySemaphore { public: void waitSemaphore(pthread_mutex_t *thread) { pthread_mutex_lock(*thread);// Makes value 1 (Not Available) }

Using a class function in int main()

佐手、 提交于 2019-12-18 07:25:05
问题 I am having problems calling my functions from my main program. These functions HAVE to be in my class. How do I access them from my int main()? #include <iostream> #include <stdio.h> #include <pthread.h> #include <stdlib.h> #include <math.h> #include <sys/types.h> #include <semaphore.h> #include <synch.h> using namespace std; class myCountingSemaphoreUsingBinarySemaphore { public: void waitSemaphore(pthread_mutex_t *thread) { pthread_mutex_lock(*thread);// Makes value 1 (Not Available) }

How can I define an UUID for a class, and use __uuidof, in the same way for g++ and Visual C++?

若如初见. 提交于 2019-12-18 06:58:42
问题 Note: This is a question-with-answer in order to document a technique that others might find useful, and in order to perhaps become aware of others’ even better solutions. Do feel free to add critique or questions as comments. Also do feel free to add additional answers. :) Visual C++ has always had a language extension __uuidof( classname ) that can retrieve an UUID , a 128 bit Universally Unique Identifier , provided that the UUID’s been associated with the class via __declspec , which also

Overloading operator% for floating types

爱⌒轻易说出口 提交于 2019-12-18 06:57:39
问题 I'm trying to overload the operator % because you can't use modulus on double types, float a = 5.0; float b = 5.0; a = a % b; // not allowed I Was trying to overload the operator % with this kind of function : template <> MyClass* MyClass<float>::operator%(Myclass &other) For other operation non involving float I use : template <class T> MyClass* MyClass<T>::operator%(MyClass &other) It never compiled actually I'm stuck and can't find a way to bypass this problem, g++ is still warning me that

Compiling with int main(void) fails; main(int argc, char *argv[]) succeeds. Why?

▼魔方 西西 提交于 2019-12-18 06:25:56
问题 Problem Why would compiling a program which has an int main(void) main function differ from compiling a program which has an int main(int argc, char *argv[]) main function, if the program does not use arguments passed on the command line? Is this OS or compiler specific? I do not get the same results using mingw and g++ (which is weird isn't it as wingw is a port of gcc) . Example Code #include <iostream> #include"SDL/SDL.h" int main(void) { return 0; } Compilation commands g++ test.cpp; #g++

Using emoji as identifier names in c++ in Visual Studio or GCC

陌路散爱 提交于 2019-12-18 05:41:36
问题 Traditionally, the accepted characters we can use as part of an identifier in C++ are _, a-z, A-Z and 0-9 after the first character. Is there a way to configure Visual Studio or GCC to accept emoji as part of the identifier names (or any other arbitrary unicode character)? int a = 2, 😊 = 3; 😊++; 😊 *= 2; int ∑(int a, int b) {return a + b;} cout << ∑(a * 😊, 3) << endl; const double π = 3.14159; double α = sin(π / 2.0); 回答1: We can see from Unicode/special characters in variable names in clang

emplace_back() does not behave as expected

*爱你&永不变心* 提交于 2019-12-18 05:28:30
问题 I wrote a simple program to play around with in-place creation of objects inside standard library containers. This is what I wrote: #include <vector> #include <iostream> class AB { public: explicit AB(int n); AB(const AB& other) = delete; AB(AB&& other); AB& operator=(const AB& other) = delete; AB& operator=(AB&& other) = default; private: int i; }; AB::AB(int n): i( n ) { std::cout << "Object created." << std::endl; }; AB::AB(AB&& other): i( std::move(other.i) ) { std::cout << "Object moved.