redefinition

PowerShell - How do I call a cmdlet in a function when overriding that cmdlet's name with the same name as the function?

℡╲_俬逩灬. 提交于 2019-11-29 03:03:26
问题 So I have a cmdlet named update-name that I have no access to change. I have created a function named update-name (the same name as the cmdlet). How do I call the cmdlet from the function with the same name? I've tried a few things and none of them seem to work. function update-name { param([string] something) #call cmdlet update-name here } There is a way to do it when it is just functions: $unBackup = 'DefaultUpdateName' if(!(Test-Path Function:\$unBackup)) { Rename-Item Function:\Update

How to redefine a Ruby constant without warning?

喜夏-厌秋 提交于 2019-11-28 16:59:14
问题 I'm running some Ruby code which evals a Ruby file every time its date changes. In the file, I have constant definitions, like Tau = 2 * Pi and, of course, they make the interpreter display the unwanted "already initialized constant" warning every time, so, I'd like to have the following functions: def_if_not_defined(:Tau, 2 * Pi) redef_without_warning(:Tau, 2 * Pi) I could avoid the warning by writing all my constant definitions like this: Tau = 2 * Pi unless defined?(Tau) but it is

Redefining or changing macro value

扶醉桌前 提交于 2019-11-28 08:26:17
I am currently working on an already developed project written in MFC C++ and am facing a problem with an already present macro having the definition: #define HEIGHT_TESTS 13 I am trying to change the value from within the code but I think since its a preprocessed definition, I am unable to do that. Is there a way I could get around this problem without having to change the original macro overall (as it might affect the original functionality of the program). I am just intending to change it in one particular condition, rest everywhere else it remains the same. Just to let everyone know, I

enable_if in template Parameters Creates Template Redefinition Error

只谈情不闲聊 提交于 2019-11-28 06:27:19
问题 In this answer what I really wanted to do is define a typename in my template parameters which could be used in the cast and return. So this: template <typename T> typename std::enable_if<sizeof(unsigned char) == sizeof(T), unsigned char>::type caster(T value){ return reinterpret_cast<unsigned char&>(value); } Would become this: template <typename T, typename R = std::enable_if<sizeof(unsigned char) == sizeof(T), unsigned char>::type > R caster(T value){ return reinterpret_cast<R&>(value); }

Override a member function with different return type

梦想与她 提交于 2019-11-27 20:33:18
Consider the example below: #include <iostream> using namespace std; class base { public: virtual int func() { cout << "vfunc in base class\n"; return 0; } }; class derived: public base { public: double func() { cout << "vfunc in derived class\n"; return 0; } }; int main() { base *bptr = new derived; bptr->func(); return 0; } The compiler gives an error for the above code that there is conflicting type for the overriden function. Why is it not possible to override a function in the derived class with a different return type ? I believe, in-order to override a function, the base class virtual

Redeclaration of global variable vs local variable

て烟熏妆下的殇ゞ 提交于 2019-11-27 13:20:24
When I compile the code below #include<stdio.h> int main() { int a; int a = 10; printf("a is %d \n",a); return 0; } I get an error: test3.c: In function ‘main’: test3.c:6:5: error: redeclaration of ‘a’ with no linkage test3.c:5:5: note: previous declaration of ‘a’ was here But if I make the variable global then it works fine. #include<stdio.h> int a; int a = 10; int main() { printf("a is %d \n",a); return 0; } Why is declaring the same global variable twice not an error, but doing that for a local variable is an error? In C, the statement int a; when made at file scope, is a declaration and a

Redefining or changing macro value

倖福魔咒の 提交于 2019-11-27 02:12:25
问题 I am currently working on an already developed project written in MFC C++ and am facing a problem with an already present macro having the definition: #define HEIGHT_TESTS 13 I am trying to change the value from within the code but I think since its a preprocessed definition, I am unable to do that. Is there a way I could get around this problem without having to change the original macro overall (as it might affect the original functionality of the program). I am just intending to change it

Override a member function with different return type

南笙酒味 提交于 2019-11-26 20:25:56
问题 Consider the example below: #include <iostream> using namespace std; class base { public: virtual int func() { cout << "vfunc in base class\n"; return 0; } }; class derived: public base { public: double func() { cout << "vfunc in derived class\n"; return 0; } }; int main() { base *bptr = new derived; bptr->func(); return 0; } The compiler gives an error for the above code that there is conflicting type for the overriden function. Why is it not possible to override a function in the derived

Redeclaration of global variable vs local variable

偶尔善良 提交于 2019-11-26 16:18:24
问题 When I compile the code below #include<stdio.h> int main() { int a; int a = 10; printf("a is %d \n",a); return 0; } I get an error: test3.c: In function ‘main’: test3.c:6:5: error: redeclaration of ‘a’ with no linkage test3.c:5:5: note: previous declaration of ‘a’ was here But if I make the variable global then it works fine. #include<stdio.h> int a; int a = 10; int main() { printf("a is %d \n",a); return 0; } Why is declaring the same global variable twice not an error, but doing that for a

C++ Redefinition Header Files (winsock2.h)

微笑、不失礼 提交于 2019-11-26 11:07:14
How do I prevent from including header files twice? The problem is I'm including the in MyClass.h and then I'm including MyClass.h in many files, so it includes multiple times and redefinition error occurs. How to prevent? I'm using #pragma once instead of include guards, and I guess that's fine. MyClass.h: // MyClass.h #pragma once #include <winsock2.h> class MyClass { // methods public: MyClass(unsigned short port); virtual ~MyClass(void); }; EDIT: Few of the errors I'm getting c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(91) : warning C4005: 'AF_IPX' : macro redefinition c