Search Results

Search found 9051 results on 363 pages for 'apply templates'.

Page 8/363 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • MOSS: Creating site templates from publishing sites

    - by nav
    Hi, On my MOSS site I am trying to save a publishing site as a site template. Then create subsites from this template. I am able to sucessfully create the site template and it is populated in the site template gallery. Following these instructions.. http://blah.winsmarts.com/2007-7-All_you_ever_wanted_to_know_about_SharePoint_2007_Site_Templates.aspx But when I try and create a subsite from this template, an error message is displayed stating: The template you have chosen is invalid or cannot be found. at Microsoft.SharePoint.Library.SPRequestInternalClass.ApplyWebTemplate(String bstrUrl, String& bstrWebTemplate, Int32& plWebTemplateId) at Microsoft.SharePoint.Library.SPRequest.ApplyWebTemplate(String bstrUrl, String& bstrWebTemplate, Int32& plWebTemplateId) Any help would be very appreciated, Thanks Nav

    Read the article

  • G++, compiler warnings, c++ templates

    - by Ian
    During the compilatiion of the C++ program those warnings appeared: c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bc:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algo.h:2317: instantiated from `void std::partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Object<double>**, std::vector<Object<double>*, std::allocator<Object<double>*> > >, _Compare = sortObjects<double>]' c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algo.h:2506: instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Object<double>**, std::vector<Object<double>*, std::allocator<Object<double>*> > >, _Size = int, _Compare = sortObjects<double>]' c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_algo.h:2589: instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Object<double>**, std::vector<Object<double>*, std::allocator<Object<double>*> > >, _Compare = sortObjects<double>]' io/../structures/objects/../../algorithm/analysis/../../structures/list/ObjectsList.hpp:141: instantiated from `void ObjectsList <T>::sortObjects(unsigned int, T, T, T, T, unsigned int) [with T = double]' I do not why, because all objects have only template parameter T, their local variables are also T. The only place, where I am using double is main. There are objects of type double creating and adding into the ObjectsList... Object <double> o1; ObjectsList <double> olist; olist.push_back(o1); .... T xmin = ..., ymin = ..., xmax = ..., ymax = ...; unsigned int n = ...; olist.sortAllObjects(xmin, ymin, xmax, ymax, n); and comparator template <class T> class sortObjects { private: unsigned int n; T xmin, ymin, xmax, ymax; public: sortObjects ( const T xmin_, const T ymin_, const T xmax_, const T ymax_, const int n_ ) : xmin ( xmin_ ), ymin ( ymin_ ), xmax ( xmax_ ), ymax ( ymax_ ), n ( n_ ) {} bool operator() ( const Object <T> *o1, const Object <T> *o2 ) const { T dmax = (std::max) ( xmax - xmin, ymax - ymin ); T x_max = ( xmax - xmin ) / dmax; T y_max = ( ymax - ymin ) / dmax; ... return ....; } representing ObjectsList method: template <class T> void ObjectsList <T> ::sortAllObjects ( const T xmin, const T ymin, const T xmax, const T ymax, const unsigned int n ) { std::sort ( objects.begin(), objects.end(), sortObjects <T> ( xmin, ymin, xmax, ymax, n ) ); }

    Read the article

  • C++ Templates: implicit conversion, no matching function for call to ctor

    - by noname
    template<class T> class test { public: test() { } test(T& e) { } }; int main() { test<double> d(4.3); return 0; } Compiled using g++ 4.4.1 with the following errors: g++ test.cpp -Wall -o test.exe test.cpp: In function 'int main()': test.cpp:18: error: no matching function for call to 'test<double>::test(double) ' test.cpp:9: note: candidates are: test<T>::test(T&) [with T = double] test.cpp:5: note: test<T>::test() [with T = double] test.cpp:3: note: test<double>::test(const test<double>&) make: *** [test.exe] Error 1 However, this works: double a=1.1; test<double> d(a); Why is this happing? Is it possible that g++ cannot implicitly convert literal expression 1.1 to double? Thanks.

    Read the article

  • Mocking a concrete class : templates and avoiding conditional compilation

    - by AshirusNW
    I'm trying to testing a concrete object with this sort of structure. class Database { public: Database(Server server) : server_(server) {} int Query(const char* expression) { server_.Connect(); return server_.ExecuteQuery(); } private: Server server_; }; i.e. it has no virtual functions, let alone a well-defined interface. I want to a fake database which calls mock services for testing. Even worse, I want the same code to be either built against the real version or the fake so that the same testing code can both: Test the real Database implementation - for integration tests Test the fake implementation, which calls mock services To solve this, I'm using a templated fake, like this: #ifndef INTEGRATION_TESTS class FakeDatabase { public: FakeDatabase() : realDb_(mockServer_) {} int Query(const char* expression) { MOCK_EXPECT_CALL(mockServer_, Query, 3); return realDb_.Query(); } private: // in non-INTEGRATION_TESTS builds, Server is a mock Server with // extra testing methods that allows mocking Server mockServer_; Database realDb_; }; #endif template <class T> class TestDatabaseContainer { public: int Query(const char* expression) { int result = database_.Query(expression); std::cout << "LOG: " << result << endl; return result; } private: T database_; }; Edit: Note the fake Database must call the real Database (but with a mock Server). Now to switch between them I'm planning the following test framework: class DatabaseTests { public: #ifdef INTEGRATION_TESTS typedef TestDatabaseContainer<Database> TestDatabase ; #else typedef TestDatabaseContainer<FakeDatabase> TestDatabase ; #endif TestDatabase& GetDb() { return _testDatabase; } private: TestDatabase _testDatabase; }; class QueryTestCase : public DatabaseTests { public: void TestStep1() { ASSERT(GetDb().Query(static_cast<const char *>("")) == 3); return; } }; I'm not a big fan of that compile-time switching between the real and the fake. So, my question is: Whether there's a better way of switching between Database and FakeDatabase? For instance, is it possible to do it at runtime in a clean fashion? I like to avoid #ifdefs. Also, if anyone has a better way of making a fake class that mimics a concrete class, I'd appreciate it. I don't want to have templated code all over the actual test code (QueryTestCase class). Feel free to critique the code style itself, too. You can see a compiled version of this code on codepad.

    Read the article

  • templates and casting operators

    - by Jonathan Swinney
    This code compiles in CodeGear 2009 and Visual Studio 2010 but not gcc. Why? class Foo { public: operator int() const; template <typename T> T get() const { return this->operator T(); } }; Foo::operator int() const { return 5; } The error message is: test.cpp: In member function `T Foo::get() const': test.cpp:6: error: 'const class Foo' has no member named 'operator T'

    Read the article

  • Speeding up templates in GAE-Py by aggregating RPC calls

    - by Sudhir Jonathan
    Here's my problem: class City(Model): name = StringProperty() class Author(Model): name = StringProperty() city = ReferenceProperty(City) class Post(Model): author = ReferenceProperty(Author) content = StringProperty() The code isn't important... its this django template: {% for post in posts %} <div>{{post.content}}</div> <div>by {{post.author.name}} from {{post.author.city.name}}</div> {% endfor %} Now lets say I get the first 100 posts using Post.all().fetch(limit=100), and pass this list to the template - what happens? It makes 200 more datastore gets - 100 to get each author, 100 to get each author's city. This is perfectly understandable, actually, since the post only has a reference to the author, and the author only has a reference to the city. The __get__ accessor on the post.author and author.city objects transparently do a get and pull the data back (See this question). Some ways around this are Use Post.author.get_value_for_datastore(post) to collect the author keys (see the link above), and then do a batch get to get them all - the trouble here is that we need to re-construct a template data object... something which needs extra code and maintenance for each model and handler. Write an accessor, say cached_author, that checks memcache for the author first and returns that - the problem here is that post.cached_author is going to be called 100 times, which could probably mean 100 memcache calls. Hold a static key to object map (and refresh it maybe once in five minutes) if the data doesn't have to be very up to date. The cached_author accessor can then just refer to this map. All these ideas need extra code and maintenance, and they're not very transparent. What if we could do @prefetch def render_template(path, data) template.render(path, data) Turns out we can... hooks and Guido's instrumentation module both prove it. If the @prefetch method wraps a template render by capturing which keys are requested we can (atleast to one level of depth) capture which keys are being requested, return mock objects, and do a batch get on them. This could be repeated for all depth levels, till no new keys are being requested. The final render could intercept the gets and return the objects from a map. This would change a total of 200 gets into 3, transparently and without any extra code. Not to mention greatly cut down the need for memcache and help in situations where memcache can't be used. Trouble is I don't know how to do it (yet). Before I start trying, has anyone else done this? Or does anyone want to help? Or do you see a massive flaw in the plan?

    Read the article

  • Reading path in templates

    - by DJPython
    Hello, is it any way to read path to current page? For example, I am at www.example.com/foo/bar/ - and I want to read '/foo/bar/'. But, all have to be done in template file without modyficating views. I have to many view files to edit each one. Sorry for my english, hope everyone understand. Cheers.

    Read the article

  • Combining regroup with get_foo_display in Django templates

    - by shacker
    I'm using the regroup template tag to group queryset output on a Choices field. In the model: RESOURCE_TYPES = ( ('tut','External tutorial'), ('read','Additional reading'), ('org','Company or organization'), ) restype = models.CharField('Resource type',max_length=6,choices=RESOURCE_TYPES) in the view: resources = Resource.objects.filter(tutorial=tutorial) in the template: {% regroup resources by restype as resource_list %} {% for type in resource_list %} <h3>{{type.grouper}}</h3> So type.grouper renders as 'tut' or 'org' on the page, rather than the long form. Normally you would use the get_foo_display syntax to get at the value of the choice, rather than the key. But the value doesn't seem to be available after going through regroup. There's no way I can find to use get_foo_display on {{type.grouper}}. It makes sense when you think about it, but what's the workaround? Thanks.

    Read the article

  • C++: Templates for static functions?

    - by Rosarch
    I have a static Utils class. I want certain methods to be templated, but not the entire class. How do I do this? This fails: #pragma once #include <string> using std::string; class Utils { private: template<class InputIterator, class Predicate> static set<char> findAll_if_rec(InputIterator begin, InputIterator end, Predicate pred, set<char> result); public: static void PrintLine(const string& line, int tabLevel = 0); static string getTabs(int tabLevel); template<class InputIterator, class Predicate> static set<char> Utils::findAll_if(InputIterator begin, InputIterator end, Predicate pred); }; Error: utils.h(10): error C2143: syntax error : missing ';' before '<' utils.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int utils.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int utils.h(10): error C2238: unexpected token(s) preceding ';' utils.h(10): error C2988: unrecognizable template declaration/definition utils.h(10): error C2059: syntax error : '<' What am I doing wrong? What is the correct syntax for this? Incidentally, I'd like to templatize the return value, too. So instead of: template<class InputIterator, class Predicate> static set<char> findAll_if_rec(InputIterator begin, InputIterator end, Predicate pred, set<char> result); I'd have: template<class return_t, class InputIterator, class Predicate> static return_t findAll_if_rec(InputIterator begin, InputIterator end, Predicate pred, set<char> result); How would I specify that: 1) return_t must be a set of some sort 2) InputIterator must be an iterator 3) InputIterator's type must work with return_t's type. Thanks.

    Read the article

  • c++ templates: problem with member specialization

    - by ChAoS
    I am attempting to create a template "AutoClass" that create an arbitrary class with an arbitrary set of members, such as: AutoClass<int,int,double,double> a; a.set(1,1); a.set(0,2); a.set(3,99.7); std::cout << "Hello world! " << a.get(0) << " " << a.get(1) << " " << a.get(3) << std::endl; By now I have an AutoClass with a working "set" member: class nothing {}; template < typename T1 = nothing, typename T2 = nothing, typename T3 = nothing, typename T4 = nothing, typename T5 = nothing, typename T6 = nothing> class AutoClass; template <> class AutoClass<nothing, nothing, nothing, nothing, nothing, nothing> { public: template <typename U> void set(int n,U v){} }; template < typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> class AutoClass: AutoClass<T2,T3,T4,T5,T6> { public: T1 V; template <typename U> void set(int n,U v) { if (n <= 0) V = v; else AutoClass<T2,T3,T4,T5,T6>::set(n-1,v); } }; and I started to have problems implementing the corresponding "get". This approach doesn't compile: template < typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> class AutoClass: AutoClass<T2,T3,T4,T5,T6> { public: T1 V; template <typename U> void set(int n,U v) { if (n <= 0) V = v; else AutoClass<T2,T3,T4,T5,T6>::set(n-1,v); } template <typename W> W get(int n) { if (n <= 0) return V; else return AutoClass<T2,T3,T4,T5,T6>::get(n-1); } template <> T1 get(int n) { if (n <= 0) return V; else return AutoClass<T2,T3,T4,T5,T6>::get(n-1); } }; Besides, it seems I need to implement get for the <nothing, nothing, nothing, nothing, nothing, nothing> specialization. Any Idea on how to solve this?

    Read the article

  • Iterating dictionary indexes in django templates

    - by unclaimedbaggage
    Hi folks...I have a dictionary with embedded objects, which looks something like this: notes = { 2009: [<Note: Test note>, <Note: Another test note>], 2010: [<Note: Third test note>, <Note: Fourth test note>], } I'm trying to access each of the note objects inside a django template, and having a helluva time navigating to them. In short, I'm not sure how to extract by index in django templating. Current template code is: <h3>Notes</h3> {% for year in notes %} {{ year }} # Works fine {% for note in notes.year %} {{ note }} # Returns blank {% endfor %} {% endfor %} If I replace {% for note in notes.year %} with {% for note in notes.2010 %} things work fine, but I need that '2010' to be dynamic. Any suggestions much appreciated.

    Read the article

  • Creating Visual Studio Templates

    - by vanja.
    I'm looking to create a Visual Studio 2008 template that will create a basic project and based on remove certain files/folders based on options the user enters. Right now, I have followed some tutorials online which have let me create the form to query the user and pass the data into an IWizard class, but I don't know what to do from there. The tutorials provide a sample to do some simple substitution: code: Form1 form = new Form1(); DialogResult dlg = form.ShowDialog(); if (dlg == DialogResult.OK) { foreach (KeyValuePair<string, string> pair in form.Parameters) { if (!replacementsDictionary.ContainsKey(pair.Key)) replacementsDictionary.Add(pair.Key, pair.Value); else replacementsDictionary[pair.Key] = pair.Value; } } form.Close(); but I'm looking to selectively include files based on the user settings, and if possible, selectively include code sections in a file based on settings. Is there a clever way to do this, or will I manually have to delete project files in the IWizard:ProjectFinishedGenerating()?

    Read the article

  • C++ Pointer member function with templates assignment with a member function of another class

    - by Agusti
    Hi, I have this class: class IShaderParam{ public: std::string name_value; }; template<class TParam> class TShaderParam:public IShaderParam{ public: void (TShaderParam::*send_to_shader)( const TParam&,const std::string&); TShaderParam():send_to_shader(NULL){} TParam value; void up_to_shader(); }; typedef TShaderParam<float> FloatShaderParam; typedef TShaderParam<D3DXVECTOR3> Vec3ShaderParam; In another class, I have a vector of IShaderParams* and functions that i want to send to "send_to_shader". I'm trying assign the reference of these functions like this: Vec3ShaderParam *_param = new Vec3ShaderParam; _param-send_to_shader = &TShader::setVector3; This is the function: void TShader::setVector3(const D3DXVECTOR3 &vec, const std::string &name){ //... } And this is the class with IshaderParams*: class TShader{ std::vector params; public: Shader effect; std::string technique_name; TShader(std::string& afilename):effect(NULL){}; ~TShader(); void setVector3(const D3DXVECTOR3 &vec, const std::string &name); When I compile the project with Visual Studio C++ Express 2008 I recieve this error: Error 2 error C2440: '=' :can't make the conversion 'void (__thiscall TShader::* )(const D3DXVECTOR3 &,const std::string &)' a 'void (__thiscall TShaderParam::* )(const TParam &,const std::string &)' c:\users\isagoras\documents\mcv\afoc\shader.cpp 127 Can I do the assignment? No? I don't know how :-S Yes, I know that I can achieve the same objective with other techniques, but I want to know how can I do this..

    Read the article

  • Why this works (Templates, SFINAE). C++

    - by atch
    Hi guys, reffering to yesterday's post, this woke me up this morning. Why this actually works? As long as the fnc test is concerned this fnc has no body so how can perform anything? Why and how this works? I'm REALLY interested to see your answers. template<typename T> class IsClassT { private: typedef char One; typedef struct { char a[2]; } Two; template<typename C> static One test(int C::*); //NO BODY HERE template<typename C> static Two test(…); //NOR HERE public: enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1 }; enum { No = !Yes }; }; Thanks in advance with help to understand this very interesting fenomena.

    Read the article

  • C++: Trouble with templates (C2064)

    - by Rosarch
    I'm having compiler errors, and I'm not sure why. What am I doing wrong here: Hangman.cpp: set<char> Hangman::incorrectGuesses() { // Hangman line 103 return Utils::findAll_if<char>(guesses.begin(), guesses.end(), &Hangman::isIncorrectGuess); } bool Hangman::isIncorrectGuess(char c) { return correctAnswer.find(c) == string::npos; } Utils.h: namespace Utils { void PrintLine(const string& line, int tabLevel = 0); string getTabs(int tabLevel); template<class result_t, class Predicate> std::set<result_t> findAll_if(typename std::set<result_t>::iterator begin, typename std::set<result_t>::iterator end, Predicate pred) { std::set<result_t> result; // utils line 16 return detail::findAll_if_rec<result_t>(begin, end, pred, result); } } namespace detail { template<class result_t, class Predicate> std::set<result_t> findAll_if_rec(typename std::set<result_t>::iterator begin, typename std::set<result_t>::iterator end, Predicate pred, std::set<result_t> result) { // utils line 25 typename std::set<result_t>::iterator nextResultElem = find_if(begin, end, pred); if (nextResultElem == end) { return result; } result.insert(*nextResultElem); return findAll_if_rec(++nextResultElem, end, pred, result); } } This produces the following compiler errors: algorithm(83): error C2064: term does not evaluate to a function taking 1 arguments algorithm(95) : see reference to function template instantiation '_InIt std::_Find_if<std::_Tree_unchecked_const_iterator<_Mytree>,_Pr>(_InIt,_InIt,_Pr)' being compiled 1> with 1> [ 1> _InIt=std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>>, 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>, 1> _Pr=bool (__thiscall Hangman::* )(char) 1> ] utils.h(25) : see reference to function template instantiation '_InIt std::find_if<std::_Tree_const_iterator<_Mytree>,Predicate>(_InIt,_InIt,_Pr)' being compiled 1> with 1> [ 1> _InIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>>, 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>, 1> Predicate=bool (__thiscall Hangman::* )(char), 1> _Pr=bool (__thiscall Hangman::* )(char) 1> ] utils.h(16) : see reference to function template instantiation 'std::set<_Kty> detail::findAll_if_rec<result_t,Predicate>(std::_Tree_const_iterator<_Mytree>,std::_Tree_const_iterator<_Mytree>,Predicate,std::set<_Kty>)' being compiled 1> with 1> [ 1> _Kty=char, 1> result_t=char, 1> Predicate=bool (__thiscall Hangman::* )(char), 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>> 1> ] hangman.cpp(103) : see reference to function template instantiation 'std::set<_Kty> Utils::findAll_if<char,bool(__thiscall Hangman::* )(char)>(std::_Tree_const_iterator<_Mytree>,std::_Tree_const_iterator<_Mytree>,Predicate)' being compiled 1> with 1> [ 1> _Kty=char, 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>, 1> Predicate=bool (__thiscall Hangman::* )(char) 1> ]

    Read the article

  • Specifying Struts templates source

    - by Chris
    Say I'm using a form with a text-field. <@s.form action="login" <@s.textfield label="E-mail" name="email"/ <@s.submit value="send"/ How can I specify that the text-form should be generated by a custom template (text_login.ftl) rather than the standard text.ftl?

    Read the article

  • wso2 governance email templates

    - by Barry Allott
    We have gotten WSO2 governance registry to send e-mails successfully. Now we want to template the emails that are being sent out. There is a sample at : http://docs.wso2.org/wiki/display/Governance450/Notification+E-mail+Customization+Sample This allows you to alter the text coming through the event but is there an easier way that writing Java code? We cannot compile the sample anyway as the Maven compiler keeps looking up the references files and errors with checksum validation failed. Thanks

    Read the article

  • problem understanding templates in c++

    - by hidayat
    Template code is not compiled until the template function is used. But where does it save the compiled code, is it saved in the object file from which used the template function in the first place? For example, main.cpp is calling a template function from the file test.h, the compiler generates an object file main.o, Is the template function inside the main.o file? because template code is not inlined, is it?

    Read the article

  • How to reduce compile time with C++ templates

    - by Shane MacLaughlin
    I'm in the process of changing part of my C++ app from using an older C type array to a templated C++ container class. See this question for details. While the solution is working very well, each minor change I make to the templated code causes a very large amount of recompilation to take place, and hence drastically slows build time. Is there any way of getting template code out of the header and back into a cpp file, so that minor implementation changes don't cause major rebuilds?

    Read the article

  • C++ templates error: instantiated from 'void TestClass::testMethod(T, std::map) [with T = SomeClass]

    - by pureconsciousness
    Hello there, I've some problem in my code I cannot deal with: #ifndef TESTCLASS_H_ #define TESTCLASS_H_' #include <map> using namespace std; template <typename T> class TestClass { public: TestClass(){}; virtual ~TestClass(){}; void testMethod(T b,std::map<T,int> m); }; template <typename T> void TestClass`<T`>::testMethod(T b,std::map<T,int> m){ m[b]=0; } #endif /*TESTCLASS_H_*/ int main(int argc, char* argv[]) { SomeClass s; TestClass<SomeClass> t; map<SomeClass,int> m; t.testMethod(s,m); } Compiler gives me following error in line m[b]=0; : instantiated from 'void TestClass::testMethod(T, std::map) [with T = SomeClass] Could you help find the problem?? Thanks in advance

    Read the article

  • C++ typedef for partial templates

    - by Gokul
    Hi, i need to do a typedef like this. template< class A, class B, class C > class X { }; template< class B, class C > typedef X< std::vector<B>, B, C > Y; I just found that it is not supported in C++. Can someone advise me on how to achieve the same through alternative means? Thanks, Gokul.

    Read the article

  • C++ enum casting and templates

    - by JP
    I get the following error with VS2008: Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast) When casting a down casting a ClassA to ClassA_1 and ClassA_1 is a templated class that received an enum for parameter such as: ClassA { virtual ~ClassA(){}; } template <class Param1> ClassA_1 : public ClassA { public: //constructor ClassA_1(Param1 p1) { _p1 = p1; } Param1 _p1; } So I have a upcasted ClassA a = new ClassA_1<myenum>(); When I need to do this: ClassA_1<myenum> a1 = (ClassA_1<myenum> a); // This fails ... The only way it works is: ClassA_1<int> a1 = (ClassA_1<int> a); but this break my template as it must always deal with int... How to properly cast a enum that is now a int, back into the enum?

    Read the article

  • Copy object using pointer (templates)

    - by Azodious
    How the push_back of stl::vector is implemented so it can make copy of any datatype .. may be pointer, double pointer and so on ... I'm implementing a template class having a function push_back almost similar to vector. Within this method a copy of argument should be inserted in internal memory allocated memory. but the argument is a pointer. (an object pointer). Can you pls tell how to create copy from pointer. so that if i delete the pointer in caller still the copy exists in my template class? Code base is as follows: template<typename T> class Vector { public: void push_back(const T& val_in) { T* a = *(new T(val_in)); m_pData[SIZE++] = a; } } Caller: Vector<MyClass*> v(3); MyClass* a = new MyClass(); a->a = 0; a->b = .5; v.push_back(a); delete a; Thanks.

    Read the article

  • Templates, interfaces (multiple inheritance) and static functions (named constructors)

    - by fledgling Cxx user
    Setup I have a graph library where I am trying to decompose things as much as possible, and the cleanest way to describe it that I found is the following: there is a vanilla type node implementing only a list of edges: class node { public: int* edges; int edge_count; }; Then, I would like to be able to add interfaces to this whole mix, like so: template <class T> class node_weight { public: T weight; }; template <class T> class node_position { public: T x; T y; }; and so on. Then, the actual graph class comes in, which is templated on the actual type of node: template <class node_T> class graph { protected: node_T* nodes; public: static graph cartesian(int n, int m) { graph r; r.nodes = new node_T[n * m]; return r; } }; The twist is that it has named constructors which construct some special graphs, like a Cartesian lattice. In this case, I would like to be able to add some extra information into the graph, depending on what interfaces are implemented by node_T. What would be the best way to accomplish this? Possible solution I thought of the following humble solution, through dynamic_cast<>: template <class node_T, class weight_T, class position_T> class graph { protected: node_T* nodes; public: static graph cartesian(int n, int m) { graph r; r.nodes = new node_T[n * m]; if (dynamic_cast<node_weight<weight_T>>(r.nodes[0]) != nullptr) { // do stuff knowing you can add weights } if (dynamic_cast<node_position<positionT>>(r.nodes[0]) != nullptr) { // do stuff knowing you can set position } return r; } }; which would operate on node_T being the following: template <class weight_T, class position_T> class node_weight_position : public node, public node_weight<weight_T>, public node_position<position_T> { // ... }; Questions Is this -- philosophically -- the right way to go? I know people don't look nicely at multiple inheritance, though with "interfaces" like these it should all be fine. There are unfortunately problems with this. From what I know at least, dynamic_cast<> involves quite a bit of run-time overhead. Hence, I run into a problem with what I had solved earlier: writing graph algorithms that require weights independently of whether the actual node_T class has weights or not. The solution with this 'interface' approach would be to write a function: template <class node_T, class weight_T> inline weight_T get_weight(node_T const & n) { if (dynamic_cast<node_weight<weight_T>>(n) != nullptr) { return dynamic_cast<node_weight<weight_T>>(n).weight; } return T(1); } but the issue with it is that it works using run-time information (dynamic_cast), yet in principle I would like to decide it at compile-time and thus make the code more efficient. If there is a different solution that would solve both problems, especially a cleaner and better one than what I have, I would love to hear about it!

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >