Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c++ - "multiple definition of..." error for a full specialisation of a template function -



have project configuration:

./main.cpp   ./type_traints/typetraints.cpp ./type_traints/typetraints.hpp ./type_traints/chapter_20.hpp 

the ./type_traints/cmakelists.txt file is:

 cmake_minimum_required (version 2.8)  add_library(chapter_20 typetraints.cpp) 

and ./cmakelists.txt follows:

cmake_minimum_required (version 2.8) project (mpl)  add_subdirectory(type_traints) include_directories(type_traints) link_directories(type_traints)  add_executable (mpl main.cpp) target_link_libraries(mpl chapter_20) 

relevant parts of files (most includes omitted) include:
./type_traints/chapter_20.hpp

#ifndef chapter_20_guard #define chapter_20_guard #include <typetraints.hpp>  void chapter_20() {   test_23(); }    #endif //chapter_20_guard 

./type_traints/typetraints.hpp

#ifndef type_traints_guard #define type_traints_guard namespace details {    template<class t> const char* class2name() {     return "unknown";   };    template<> const char* class2name<int>() {     return "int";   }; }  template<class t> class type_descriptor {   friend std::ostream& operator << (std::ostream& stream,                                      const type_descriptor<t>& desc) {     stream << desc.getname();     return stream;   }  public:   std::string getname() const;   };  template<class t> std::string type_descriptor<t>::getname() const {   return details::class2name<t>(); }  void test_23();     #endif // type_traints_guard 

./type_traints/typetraints.cpp

#include<typetraints.hpp>  void test_23() {   cout << type_descriptor<int>() << endl; } 

and ./main.cpp

#include <chapter_20.hpp>  int main(int argc, char* argv[]) { chapter_20();   return 0; } 

the project compiles fails link:

[ 50%] building cxx object type_traints/cmakefiles/chapter_20.dir/typetraints.cpp.o linking cxx static library libchapter_20.a [ 50%] built target chapter_20 [100%] building cxx object cmakefiles/mpl.dir/main.cpp.o linking cxx executable mpl type_traints/libchapter_20.a(typetraints.cpp.o): in function `char const* details::cl ass2name<int>()':                                                                    /home/marcin/projects/mpl/type_traints/typetraints.hpp:312: multiple definition of `c har const* details::class2name<int>()'                                               cmakefiles/mpl.dir/main.cpp.o:/home/marcin/projects/mpl/type_traints/typetraints.hpp: 312: first defined here                                                              collect2: ld returned 1 exit status make[2]: *** [mpl] błąd 1 make[1]: *** [cmakefiles/mpl.dir/all] error 2 make: *** [all] error 2 23:56:20@marcin-laptop ~/p 

the project links fine if remove class2name specialization (class2name<int>()) typetraints.hpp , use generic implementation.

does have idea why that? did miss-configure cmake files?

in short: explicitly (i.e. fully) specialized template function is no longer template. ordinary function , obeys 1 definition rule ordinary functions.

in other words can't define explicitly specialized function templates in header file. doing result in odr violations.

a template template long depends on @ least 1 parameter. i.e. partial specializations can defined in header files (since still templates). explicit (i.e. full) specializations can declared in header files, have defined in implementation files, ordinary functions.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -