c++-address

Pointer will randomly print it's address instead of it's pointed value, C++

烂漫一生 提交于 2020-01-08 03:06:07
问题 So I have this problem where the output prints the address of my pointer, I have no idea why this happens cuz the pointers is not modified at all Heres the code: using namespace std; class AndroideAbstracto { protected: int *vida; int *fuerza; int *velocidad; public: void setvalores(int vi, int fu, int ve) { velocidad = &ve; vida = &vi; fuerza = &fu; }; virtual void imprimir(void) = 0; }; class Androide : public AndroideAbstracto { public: void imprimir() { std::cout << "Caracteristicas del

Addresses of identical function template instantiations across compilation units

若如初见. 提交于 2019-11-27 22:28:49
Why does this work? I see similar SO questions stating that it does, but could someone explain it in more detail? Particularly, is this behavior protected by a standard? i.h #ifndef I_H_ #define I_H_ typedef void (*FuncPtr)(); template<typename T> void FuncTemplate() {} class C {}; #endif a.cc #include "i.h" FuncPtr a() { return &FuncTemplate<C>; } b.cc #include "i.h" FuncPtr b() { return &FuncTemplate<C>; } m.cc #include <iostream> #include "i.h" FuncPtr a(); FuncPtr b(); int main() { std::cout << (a() == b() ? "equal" : "not equal") << std::endl; return 0; } Then $ g++ -c -o a.o a.cc $ g++

Addresses of identical function template instantiations across compilation units

旧巷老猫 提交于 2019-11-26 23:11:31
问题 Why does this work? I see similar SO questions stating that it does, but could someone explain it in more detail? Particularly, is this behavior protected by a standard? i.h #ifndef I_H_ #define I_H_ typedef void (*FuncPtr)(); template<typename T> void FuncTemplate() {} class C {}; #endif a.cc #include "i.h" FuncPtr a() { return &FuncTemplate<C>; } b.cc #include "i.h" FuncPtr b() { return &FuncTemplate<C>; } m.cc #include <iostream> #include "i.h" FuncPtr a(); FuncPtr b(); int main() { std: