Results 1 to 3 of 3

Thread: templates

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Aug:2012
    Location:
    Posts: 297

    templates

    , templates C++. : -
    Code:
    template <class T>
    typedef T (*function_template)(T, T)
    ?
    ,
    Code:
    function_template<double> f
    , :
    Code:
    double f(double, double)

    Code:
    template <class T>

    Code:
    template <typename T>
    ?
    Code:
     
    void fon(int a)
    {
    cout << a << endl;
    }

    Code:
    fon('192');
    . , , . , - 3225906 . , - , .

    . :
    Code:
    int a;
    cout << a;
    , ,
    Code:
    int a = int();
    cout << a;
    0. , default int, ?
    , class Car { ....}

    Code:
    Car my_car;
    default ?
    .

  2. #2
    Registered User
    Join Date: Aug:2003
    Location:
    Posts: 175
    , template typedef . C++11 using:
    Code:
    template <class T> using foo = T(T,T);
    template <class T> using bar = T(*)(T,T);
    
    double mix(foo<double> f, bar<int> g)
    {
      return f(2.5,3.75)+g(4,5);
    }
    double ddd(double a, double b) { return a*b; }
    int    nnn(int    a, int    b) { return a^b; }
    
    void main() {std::cout<<mix(ddd,nnn); }
    foo<> T- . bar<T> . C++98, typedef- . :
    Code:
    template <class > struct baz { typedef T t(T,T); };
    template <class > struct bag { typedef T (*t)(T,T); };
    baz<T>::t bag<T>::t. "typename baz<T>::t".



    :
    Code:
    template <class T> ...
    template <typename T> ...
    . , . (typename) , , , class .



    Code:
    fon('192');
    . . Visual Studio- int - , . , : 3225906 0x313932, ASCII '1', '9' '2'. , ( , ).



    . : , . int() , 0/0.0/false. -: . template-:
    Code:
    template <class T> void f()
    {
      T x = T();
    }
    x , . "T x;", default- , . .

    ( MSVS ) . C++11 . , .

    . Visual C++ GCC.

  3. #3
    Registered User
    Join Date: Aug:2012
    Location:
    Posts: 297
    , . , new :
    Code:
    double* pointer = new double[100]();
    double- 0. , ( () ) default ? 2 . - ? default- .
    , , :
    Code:
    Polynomial Polynomial::operator*(double number)
    {
    	Polynomial result = *this;
    	for (size_t i = 0; i <= degree; ++i)
    	{
    		result.coefficients[i] *= number;
    	}
    
    	return result;
    }
    
    Polynomial operator*(double number, /* const */ Polynomial& other)  //   ?
    {
    	return other*number;
    }
    (.., ). , - "Error 1 error C2678: binary '*' : no operator found which takes a left-hand operand of type 'const Polynomial' (or there is no acceptable conversion)" .
    const( -) . , const , . , . . 1-2 const, , .
    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |