Search Results

Search found 3595 results on 144 pages for 'templates deduction'.

Page 48/144 | < Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >

  • C++ rvalue temporaries in template

    - by aaa
    hello. Can you please explain me the difference between mechanism of the following: int function(); template<class T> void function2(T&); void main() { function2(function()); // compiler error, instantiated as int & const int& v = function(); function2(v); // okay, instantiated as const int& } is my reasoning correct with respect to instantiation? why is not first instantiated as const T&? Thank you

    Read the article

  • Why can't I create a templated sublcass of System::Collections::Generic::IEnumerable<T>?

    - by fiirhok
    I want to create a generic IEnumerable implementation, to make it easier to wrap some native C++ classes. When I try to create the implementation using a template parameter as the parameter to IEnumerable, I get an error. Here's a simple version of what I came up with that demonstrates my problem: ref class A {}; template<class B> ref class Test : public System::Collections::Generic::IEnumerable<B^> // error C3225... {}; void test() { Test<A> ^a = gcnew Test<A>(); } On the indicated line, I get this error: error C3225: generic type argument for 'T' cannot be 'B ^', it must be a value type or a handle to a reference type If I use a different parent class, I don't see the problem: template<class P> ref class Parent {}; ref class A {}; template<class B> ref class Test : public Parent<B^> // no problem here {}; void test() { Test<A> ^a = gcnew Test<A>(); } I can work around it by adding another template parameter to the implementation type: ref class A {}; template<class B, class Enumerable> ref class Test : public Enumerable {}; void test() { using namespace System::Collections::Generic; Test<A, IEnumerable<A^>> ^a = gcnew Test<A, IEnumerable<A^>>(); } But this seems messy to me. Also, I'd just like to understand what's going on here - why doesn't the first way work?

    Read the article

  • Force type of C++ template

    - by gregseth
    Hi, I've a basic template class, but I'd like to restrain the type of the specialisation to a set of classes or types. e.g.: template <typename T> class MyClass { .../... private: T* _p; }; MyClass<std::string> a; // OK MYCLass<short> b; // OK MyClass<double> c; // not OK Those are just examples, the allowed types may vary. Is that even possible? If it is, how to do so? Thanks.

    Read the article

  • C++ Template Usage

    - by MalcomTucker
    If I have a template definition like the one below, can someone provide a code sample for how I would actually instantiate an instance of this with two of my own classes? template <class T1, class T2> class LookUpTable { public: LookUpTable(); void set(Tl x, T2* y); T2* get(Tl x); }; Thanks.

    Read the article

  • Can the template parameters of a constructor be explicitly specified?

    - by sth
    A constructor of a class can be a template function. At the point where such a constructor is called, the compiler usually looks at the arguments given to the constructor and determines the used template parameters from them. Is there also some syntax to specify the template parameters explicitly? A contrived example: struct A { template<typename T> A() {} }; Is there a way to instantiate this class? What is the syntax to explicitly specify the constructor's template parameters? My use case would be a problem were the compiler doesn't seem to find the correct templated constructor. Explicitly specifying the template parameters would probably generate more useful error messages or even resolve the problem.

    Read the article

  • Optimal template for change content via XMLHTTPRequest with JQuery,PHP,SQL [closed]

    - by B.F.
    This is my method to handle XMLHTTPRequests. Avoids mysql request, foreign access, nerves user, double requests. jquery var allow=true; var is_loaded=""; $(document).ready(function(){ .... $(".xx").on("click",functio(){ if(allow){ allow=false; if(is_loaded!="that"){ $.post("job.php", {job:"that",word:"aaa",number:"123"},function(data){ $(".aaa").html(data); is_loaded="that"; }); } setTimeout(function(){allow=true},500); } .... }); job.php <?PHP ob_start('ob_gzhandler'); if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) or strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')exit("bad boy!"); if($_POST['job']=="that"){ include "includes/that.inc; } elseif($_POST['job']== .... ob_end_flush(); ?> that.inc if(!preg_match("/\w/",$_POST['word'])exit("bad boy!"); if(!is_numeric($_POST['number'])exit("bad boy!"); //exclude more. $path="temp/that_".$row['word']."txt"; if(file_exists($path) and filemtime("includes/that.inc")<$filemtime($path)){ readfile($path); } else{ include "includes/openSql.inc"; $call=sql_query("SELECT * FROM that WHERE name='".mysql_real_escape_string($_POST['word'])."'"); if(!$call)exit("ups"); $out=""; while($row=mysql_fetch_assoc($call)){ $out.=$_POST['word']." loves the color ".$row['color'].".<br/>"; } echo $out; $fn=fopen($path,"wb"); fputs($fn,$out); fclose($fn); } if something change at the database, you just have to delete involved files. Hope it was English.

    Read the article

  • Magento CSS not Loading in New Template

    - by vulgarbulgar
    I have posted on the template creator's site, as well as Magento support, but no one has responded. The CSS is not loading at all on the custom theme I have installed, which is supposedly compatible with the current version of Magento. You can view the page here: shop.dearearth.net This is a fresh installation of Magento and the theme, with a fresh database. I have a feeling it should be a relatively quick fix. Thanks for looking.

    Read the article

  • In a C++ template, is it allowed to return an object with specific type parameters?

    - by nieldw
    When I've got a template with certain type parameters, is it allowed for a function to return an object of this same template, but with different types? In other words, is the following allowed? template<class edgeDecor, class vertexDecor, bool dir> Graph<edgeDecor,int,dir> Graph<edgeDecor,vertexDecor,dir>::Dijkstra(vertex s, bool print = false) const { /* Construct new Graph with apropriate decorators */ Graph<edgeDecor,int,dir> span = new Graph<edgeDecor,int,dir>(); /* ... */ return span; }; If this is not allowed, how can I accomplish the same kind of thing?

    Read the article

  • 7 - drupal overriding theme fucntions gettting notices

    - by welovedesign
    So I am overriding a theme function by putting the contents in my template.php module, the problem is that it it throwing up loads of undefined index notices because there are lots of functions that are defined in the module. How can I define these in the template.php file and prevent the notices. Note: I know i can turn them off 'uc_cart_block_content' => array( 'variables' => array( 'help_text' => NULL, 'items' => NULL, 'item_count' => NULL, 'item_text' => NULL, 'total' => NULL, 'summary_links' => NULL, 'collapsed' => TRUE, ), 'file' => 'uc_cart.theme.inc', ),

    Read the article

  • Class templating std::set key types

    - by TomFLuff
    I have a class to evaluate set algebra but wish to template it. At the minute it looks a bit like this set.h: template<typename T> class SetEvaluation { public: SetEvaluation<T>(); std::set<T> evaluate(std::string in_expression); } set.cpp template<typename T> std::set<T> SetEvaluation<T>::evaluate(std::string expression) { std::set<T> result; etc etc... } But i'm getting undefined reference errors when compiling. Is it possible to declare the return type as std::set<T> and then pass std::string as the class template param. There are no errors in the class but only when I try to instantiate SetEvaluation<std::string> Can anyone shed light on this problem? thanks

    Read the article

  • Template specialization to use default type if class member typedef does not exist

    - by Frank
    Hi Everyone, I'm trying to write code that uses a member typedef of a template argument, but want to supply a default type if the template argument does not have that typedef. A simplified example I've tried is this: struct DefaultType { DefaultType() { printf("Default "); } }; struct NonDefaultType { NonDefaultType() { printf("NonDefault "); } }; struct A {}; struct B { typedef NonDefaultType Type; }; template<typename T, typename Enable = void> struct Get_Type { typedef DefaultType Type; }; template<typename T> struct Get_Type< T, typename T::Type > { typedef typename T::Type Type; }; int main() { Get_Type::Type test1; Get_Type::Type test2; } I would expect this to print "Default NonDefault", but instead it prints "Default Default". My expectation is that the second line in main() should match the specialized version of Get_Type, because B::Type exists. However, this does not happen. Can anyone explain what's going on here and how to fix it, or another way to accomplish the same goal? Thank you.

    Read the article

  • Is it possible to supply template parameters when calling operator()?

    - by Paul
    I'd like to use a template operator() but am not sure if it's possible. Here is a simple test case that won't compile. Is there something wrong with my syntax, or is this simply not possible? struct A { template<typename T> void f() { } template<typename T> void operator()() { } }; int main() { A a; a.f<int>(); // This compiles. a.operator()<int>(); // This compiles. a<int>(); // This won't compile. return 0; }

    Read the article

  • templated class : accessing derived normal-class methods

    - by user1019129
    I have something like this : class Container1 { public: method1() { ... } } class Container2 { public: method1() { ... } } template<class C = Container1> class X : public C { public: using C::method1(); ..... X(string& str) : C(str) {}; X& other_method() { method1(); ...; } } My question is why I have to use "using C::method1()", to be able to access the method.. Most of answers I found is for the case where templated-class inhering templated-class. Normally they mention using "this-", but this does not seem to work in this case. Can I do something else shorter... Also I'm suspecting the other error I'm getting is related to the same problem : no match call for (X<Container1>) (<std::string&>)

    Read the article

  • C++ Template Classes and Copy Construction

    - by themoondothshine
    Is there any way I can construct an new object from the given object if the template parameters of both objects are identical at run-time? For example: I have a template class with the declaration: template<typename _Type1, typename _Type2> class Object; Next, I have two instantiations of the template: template class Object<char, int>; template class Object<wchar_t, wint_t>; Now, I want to write a member function such as: template<typename _Type1, typename _Type2> Object<char, int> Object<_Type1, _Type2>::toCharObject() { if(__gnu_cxx::__are_same<_Type1, char>::__value) return *this; else { //Perform some kind of conversion and return an Object<char, int> } } I have tried a couple of techniques, such as using __gnu_cxx::__enable_if<__gnu_cxx::__are_same<_Type1, char>::__value, _Type1>::__type in a copy constructor for the Oject class, but I keep running into the error: error: conversion from ‘Object<wchar_t, wint_t>’ to non-scalar type ‘Object<char, int>’ requested Is there no way I can do this? Any help will be greatly appreciated!

    Read the article

  • class T in c++ (your definition)

    - by JohnWong
    The one advantage of using class T in c++ is to reduce the time to redefine data types in a function, if those data types are defined in other function, for example, in int main. template <class T> void showabs(T number) { if (number < 0 ) number = -number; cout << number << endl; return 0; } int main() { int num1 = -4; float num2 = -4.23f; showabs(num1); showabs(num2); return 0; } So in this case, without class T, for each data type, we have to add its corresponding data-type condition, that is, another set of if statement for int, and another one for float. Am I correct?

    Read the article

  • Checking if a function has C-linkage at compile-time [unsolvable]

    - by scjohnno
    Is there any way to check if a given function is declared with C-linkage (that is, with extern "C") at compile-time? I am developing a plugin system. Each plugin can supply factory functions to the plugin-loading code. However, this has to be done via name (and subsequent use of GetProcAddress or dlsym). This requires that the functions be declared with C-linkage so as to prevent name-mangling. It would be nice to be able to throw a compiler error if the referred-to function is declared with C++-linkage (as opposed to finding out at runtime when a function with that name does not exist). Here's a simplified example of what I mean: extern "C" void my_func() { } void my_other_func() { } // Replace this struct with one that actually works template<typename T> struct is_c_linkage { static const bool value = true; }; template<typename T> void assertCLinkage(T *func) { static_assert(is_c_linkage<T>::value, "Supplied function does not have C-linkage"); } int main() { assertCLinkage(my_func); // Should compile assertCLinkage(my_other_func); // Should NOT compile } Is there a possible implementation of is_c_linkage that would throw a compiler error for the second function, but not the first? I'm not sure that it's possible (though it may exist as a compiler extension, which I'd still like to know of). Thanks.

    Read the article

  • C++ template + typedef

    - by MMS
    What is wrong in the following code: Point2D.h template <class T> class Point2D { private: T x; T y; ... }; PointsList.h template <class T> class Point2D; template <class T> struct TPointsList { typedef std::vector <Point2D <T> > Type; }; template <class T> class PointsList { private: TPointsList <T>::Type points; //Compiler error ... }; I would like to create new user type TPointsList without direct type specification...

    Read the article

  • How to loop X times in Django?

    - by Mark
    I have user reviews on my site. Each review has a rating of 1-5 stars. I want to print that many stars. How do I do it? I only see {% for X in Y %} which lets you iterate over a list, but not a certain number of times.

    Read the article

  • Django: Is it possible to attach media files (css, javascript etc) to a View-class?

    - by mrmclovin
    I can't fins any information on how to define css or javascript files in a view like: class MyView(View): .... class Media: css = { 'all' : 'mystyle.css' } If you have a form you can do like: class MyForm(ModelForm): .... class Media: css = { 'all' : 'mystyle.css' } And then in the template you can print the files like; {{ form.media.css }} I like that Syntax very much and I like to keep the View-specific css files in the app-directory. Does anyone know if it's possible? Thanks!

    Read the article

  • Will the template argument's destructor to a templated class be called on deletion?

    - by Mutmansky
    If you have a templated base class as in the following example: class A{ A(); virtual ~A(); }; template <class T> class B : public T { B(); virtual ~B(); }; typedef B<A> C; class D : public C { D(); virtual ~D(); }; When you delete an instance of D, will the destructor of A be called? I'll probably create a test program to find out what happens, but just thinking about it, I wasn't sure what should happen.

    Read the article

< Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >