Jump to content
  • Advertisement

Si_con

Member
  • Content Count

    23
  • Joined

  • Last visited

Community Reputation

100 Neutral

About Si_con

  • Rank
    Member
  1. Thanks i will follow your advice, i told because i find very confusing which executables i should add to the ide, because in the sdk there is the toolchain directory, in which there are x86 and arm-linux-androideabi, i dont know if that is refered to which platform is executed the compiler, or which is the target platform. Also inside of each one there are two bin directories
  2. Si_con

    Cross reference in the same header

    if there are much declarations to put before the class, is a good practice to put all that declarations in a file and include it just before the main class declaration? something like that so it doesn't look so messy: namespace NS { #include "Foo_decl.h" class Foo { ... };
  3. Si_con

    Cross reference in the same header

    i think i realized that float Func(const Foo& f1,const Foo& f2) has to be in the cpp file, not in header as it was a templated function?
  4. I have that: #ifndef _FOO_H_ #define _FOO_H_ namespace NS { class Foo; float Func(const Foo& f1,const Foo& f2); class Foo { public: float a,b; Foo() {}; Foo(float n1,float n2):a(n1),b(n2) { }; Foo(const Foo& foo):a(foo.a),b(foo.b) { }; ~Foo() {}; const Foo& operator = (const Foo& foo) { a = foo.a; b = foo.b; return *this; } const Foo& operator * (const Foo& foo) { a *= foo.a; b *= foo.b; return *this; } // Here float NS::Func(const NS::Foo&,const NS::Foo&) is known? float Func(const Foo& foo) { return NS::Func(*this,foo); } }; float Func(const Foo& f1,const Foo& f2) { return f1.a*f2.a + f1.b*f2.b; } }; // namespace end #endif Im calling a function of the same namespace as the class, inside a member of the class, and that function take that class reference as arguments, im trying to make that work and put the declaration of class and external function on the top, so they are know in the rest of the file, but i still get errors, like this one: multiple definition of `NS::Func(NS::Foo const&, NS::Foo const&)'| How that can be done right ?
  5. How i can configure the Android ndk for using the tools on an free development ide like the Code::blocks?
  6. Si_con

    Template friend operator

    Im using Code blocks with gcc and i have tried also with the vc++ but give me errors too. Thanks, this version with the operator inline works, although still would like to know why the other is not working in some compilers as it seems
  7. Si_con

    Template friend operator

    if i compile that code it tells me: main.cpp|32|error: declaration of 'class T'| and main.cpp|8|error: shadows template parm 'class T'|
  8. Si_con

    Template friend operator

    I read that is needed to put that <>, without it doesn't work also http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16
  9. Si_con

    Template friend operator

    the friend operator part: friend const Foo<T> operator* <> (const int k, const Foo<T>& foo); Foo.h|35|error: declaration of 'operator*' as non-function| Foo.h|35|error: expected ';' before '<' token|
  10. I have problems trying to make a templated friend operator, i have searched on internet and they put that putting the declarations before the class, and the <> after the operator symbol it works, but i cant get that working, what im doing wrong? which is the right way of making a templated friend operator? #ifndef _FOO_H_ #define _FOO_H_ template <class T> class Foo; template <class T> const Foo<T> operator * (const int k, const Foo<T>& foo); template <class T> class Foo { private: T a,b; public: Foo() {}; Foo(T n1,T n2):a(n1),b(n2) { }; Foo(const Foo& foo):a(foo.a),b(foo.b) { }; ~Foo() {}; const Foo<T>& operator = (const Foo<T>& foo) { a = foo.a; b = foo.b; return *this; }; const Foo<T>& operator * (const Foo<T>& foo) { a *= foo.a; b *= foo.b; return *this; }; const Foo<T> operator * (const Foo<T>& foo) const { return Foo<T>(foo.a, foo.b); }; // template <class T> friend const Foo<T> operator* <> (const int k, const Foo<T>& foo); }; template <class T> const Foo<T> operator * (const int k, const Foo<T>& foo) { return Foo<T>(foo.a*k, foo.b*k); }; #endif
  11. Si_con

    Counting number of class instances

    Thank you all, works good with const in cpp file and extern in header
  12. Si_con

    Counting number of class instances

    so i have to declare the constant in the cpp file, and later how i use it outside?
  13. Si_con

    Counting number of class instances

    yes i made a A.cpp file that only includes the A.h file, only for can compile the class to seek errors, im using code blocks with myngw
  14. Si_con

    Counting number of class instances

    then even with preprocessor #ifndef/#endif each time you include the file it calls the const variables constructor? i though because of being const it was only called once
  15. Si_con

    Counting number of class instances

    File: A.h #ifndef _A_H_ #define _A_H_ template <class T> class A { private: static unsigned int numinstances; T a,b; public: A() { numinstances++; }; A(T n1,T n2):a(n1),b(n2) { numinstances++; }; A(const A& aa):a(aa.a),b(aa.b) { numinstances++; } ~A() { numinstances--; }; static unsigned int getNumInstances(); }; template <class T> unsigned int A<T>::numinstances = 0; template <class T> unsigned int A<T>::getNumInstances() { return numinstances; }; const A<int> a = A<int>(0,0); #endif File: main.cpp #include <iostream> #include "A.h" using namespace std; int main() { cout << A<int>::getNumInstances() << endl; return 0; } This output: 2
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!