visual-c++

C++ Explicit templated function instantiation for templated class of different type

陌路散爱 提交于 2021-01-27 06:57:50
问题 I am trying to explicitly instantiate a templated function of type U inside a templated class of type T. My code below generates a warning and the linker does not find the explicit instantiation of ReinterpretAs() . Can anyone spot the error or advise on how to do this? I am using VC++ 2010. template<typename T> class Matrix { public: template<typename U> Matrix<U> ReinterpretAs() const; }; template<typename T> template<typename U> Matrix<U> Matrix<T>::ReinterpretAs() const { Matrix<U> m; //

How to use tlb files in a native C++ project

假如想象 提交于 2021-01-27 05:59:36
问题 I have a tlb files that contains some function declaration that I need to use. If I use #import "type_library.tlb" I can correclty reference the function from my code: tlb_namespace::required_function(); But when I compile the project the linker says that tlb_namespace::required_function is an unresolved external symbol. How can I succesfully build this kind of project? EDIT : I have used the same type library in a Dummy VBA access project. I have added the reference to the type library and I

How to use tlb files in a native C++ project

跟風遠走 提交于 2021-01-27 05:59:15
问题 I have a tlb files that contains some function declaration that I need to use. If I use #import "type_library.tlb" I can correclty reference the function from my code: tlb_namespace::required_function(); But when I compile the project the linker says that tlb_namespace::required_function is an unresolved external symbol. How can I succesfully build this kind of project? EDIT : I have used the same type library in a Dummy VBA access project. I have added the reference to the type library and I

How to use tlb files in a native C++ project

▼魔方 西西 提交于 2021-01-27 05:59:12
问题 I have a tlb files that contains some function declaration that I need to use. If I use #import "type_library.tlb" I can correclty reference the function from my code: tlb_namespace::required_function(); But when I compile the project the linker says that tlb_namespace::required_function is an unresolved external symbol. How can I succesfully build this kind of project? EDIT : I have used the same type library in a Dummy VBA access project. I have added the reference to the type library and I

std::string allocate memory 2 times for 1 string

烂漫一生 提交于 2021-01-27 05:40:34
问题 #include <iostream> #include <string> void* operator new(size_t size) { std::cout << "Allocated: " << size << " Bytes\n"; return malloc(size); } void operator delete(void* var) { std::cout << "Deleted\n"; free(var); } int main() { std::string name0 = "Ahmed Zaki Marei"; //std::string name1 = "Lara Mohammed"; std::cout << name0 << "\n"; //std::cout << name1 << "\n"; } When I try to run this code it gives me this output: Allocated: 8 Bytes Allocated: 32 Bytes Ahmed Zaki Marei Deleted Deleted

Forward declaring a function in a namespace inside another function in that namespace

自作多情 提交于 2021-01-27 04:51:30
问题 I have two source files, a.cpp and b.cpp . In a.cpp , I have a function, foo : namespace ns { void foo() { std::cout << "foo!"; } } In b.cpp , I have another function in namespace ns in which I'd like to prototype and call foo : namespace ns { void bar() { void foo(); foo(); } } While the above is syntactically valid, it leads the compiler to think that foo is in the global namespace (or at least that's what I've deduced from the linker errors I get when I do this). My first two ideas to fix

Forward declaring a function in a namespace inside another function in that namespace

喜夏-厌秋 提交于 2021-01-27 04:51:08
问题 I have two source files, a.cpp and b.cpp . In a.cpp , I have a function, foo : namespace ns { void foo() { std::cout << "foo!"; } } In b.cpp , I have another function in namespace ns in which I'd like to prototype and call foo : namespace ns { void bar() { void foo(); foo(); } } While the above is syntactically valid, it leads the compiler to think that foo is in the global namespace (or at least that's what I've deduced from the linker errors I get when I do this). My first two ideas to fix

filling up an array in c++ [closed]

╄→гoц情女王★ 提交于 2021-01-27 04:27:12
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I am new to c++ . I was trying to write following code to fill up each byte of array with new values without overriding others. Each

filling up an array in c++ [closed]

夙愿已清 提交于 2021-01-27 04:26:32
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I am new to c++ . I was trying to write following code to fill up each byte of array with new values without overriding others. Each

Lambda Capture by Value forces all scoped object to const

我的未来我决定 提交于 2021-01-27 03:56:18
问题 I was intending to write a memorization pattern in C++ and ended up with the following approach std::function<int(int)> Memoize(std::function<int(int)> fn) { std::map<int, int> memo; std::function<int(int)> helper = [=](int pos) { if (memo.count(pos) == 0) { memo[pos] = fn(pos); } return memo[pos]; }; return helper; } Strangely, my compiler VS 2012, refused to compile with the following error 1>Source1.cpp(24): error C2678: binary '[' : no operator found which takes a left-hand operand of