我在Visual Studio 2008专业版中创建了一个项目.
这个项目为每个分配包含一个.cpp文件,如下所示......
[-]Source Files
\
|-- 233.cpp
|-- test.cpp
Run Code Online (Sandbox Code Playgroud)
每个文件都包含main()的定义.
操作:CTRL + F5
Error 1 error LNK2005: _main already defined in 233.obj test.obj
Error 2 fatal error LNK1169: one or more multiply defined symbols found
Run Code Online (Sandbox Code Playgroud)
如何编译并查看每个文件的输出?
谢谢.
是否可以投影对象的每个属性并添加更多内容,而无需专门列出所有属性.例如,而不是这样做:
var projection = from e in context.entities
select new QuestionnaireVersionExtended
{
Id = e.Id,
Version = e.Version,
CreationDate = e.CreationDate,
...
many more properties
...
NumberOfItems = (e.Children.Count())
};
Run Code Online (Sandbox Code Playgroud)
我们可以做这样的事情:
var projection = from e in context.entities
select new QuestionnaireVersionExtended
{
e,
NumberOfItems = (e.Children.Count())
};
Run Code Online (Sandbox Code Playgroud)
在哪里从e获取具有相同名称的每个属性,并在其上添加"NumberOfItems"属性?
在调试F#应用程序时,我希望能够从VS2010立即窗口调用F#方法,但它似乎不起作用.问题似乎是F#方法实际上是FSharpFunc对象.我尝试使用"调用"方法,但交互式窗口无法识别它.
所以我正在玩EnvDTE,和EnvDTE.CodeModelAPI,我想知道是否有办法获得由a表示的文本值CodeElement.
假设我有一个CodeAttribute,是否有某种方法来获得代表string的东西CodeAttribute,即[MyAttribute(value="myvalue")].
我知道可以使用它的各种属性来重构代码CodeElement,至少在某些情况下,但是对于某些事情来说,似乎更容易获得文本.
谢谢!
只是想我会分享这个以防万一其他人遇到这个.
我今天做了类似的事情,花了一些时间来弄清楚为什么这会在运行时引起问题.
这段代码:
Public Class foo
Public bar As String = "blah"
End Class
Public Sub DoInline()
Dim o As New foo
Dim f As Func(Of String)
With o
f = Function() .bar
End With
Try
Console.WriteLine(f.DynamicInvoke())
Catch ex As Reflection.TargetInvocationException
Console.WriteLine(ex.InnerException.ToString)
End Try
End Sub
Run Code Online (Sandbox Code Playgroud)
抛出NullReferenceException.似乎With使用闭包作为其临时存储,并且在"End With"中,它将闭包的变量设置为Nothing.
这是RedGate Reflector中的代码:
Public Shared Sub DoInline()
Dim o As New foo
Dim $VB$Closure_ClosureVariable_7A_6 As New _Closure$__1
$VB$Closure_ClosureVariable_7A_6.$VB$Local_VB$t_ref$L0 = o
Dim f As Func(Of String) = New Func(Of String)(AddressOf $VB$Closure_ClosureVariable_7A_6._Lambda$__1)
$VB$Closure_ClosureVariable_7A_6.$VB$Local_VB$t_ref$L0 = Nothing …Run Code Online (Sandbox Code Playgroud) 当我在Visual Studio 2010中工作时,IDE似乎随机切换到"Scroll Lock"模式.这是一个我不知道的新功能(由某些指定的键/鼠标单击启动)还是一个错误?我猜这实际上是我系统上的计算机/硬件故障,但想检查是否有其他人遇到此问题?
在我处于这种"模式"之后,我似乎无法摆脱它.我已经尝试过多次打开/关闭ScrLk,突出显示文本等等.我疯狂地点击了"我的出路",但不知道如何.此时,我唯一的选择是关闭IDE并重新启动,然后一切都恢复正常.
我们有一些旧的C代码,具有预ANSI(K&R风格)函数声明.例如:
int foo(x, y)
double x, y;
{
/* do some stuff */
}
Run Code Online (Sandbox Code Playgroud)
是否有编译器开关在Visual C++ 2008中启用对此的支持?
给出以下代码:
template <typename T>
struct Wrapper {
T value;
Wrapper(T val) : value(val) {}
}
int main() {
Wrapper<int> x(42);
int y = x; // need solution for y = x.value
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法实现分配
int y = x;
Run Code Online (Sandbox Code Playgroud)
所以它意味着y = x.value.
我知道重载赋值运算符本身是不可能的,因为它适用于赋值左侧的对象,而标准不允许带有两个参数的friend函数.
如果通过重载任何其他运算符或使用一些特殊技巧无法做到这一点,除非通过调用Wrapper类提供的get方法,除非通过调用Wrapper类提供的get方法,否则将如何实现:
int y = x.get();
Run Code Online (Sandbox Code Playgroud) Dictionary<string, string> optionDictionary = new Dictionary<string, string>();
optionDictionary = ....;
SortedDictionary<string, string> optionsSorted;
if(sorting)
{
optionsSorted = new SortedDictionary<string, string>(optionDictionary );
// Convert SortedDictionary into Dictionary
}
return optionDictionary ;
Run Code Online (Sandbox Code Playgroud) 我即将开始阅读大量的二进制文件,每个文件有1000个或更多记录.不断添加新文件,因此我正在编写Windows服务来监视目录并处理收到的新文件.这些文件是用c ++程序创建的.我在c#中重新创建了结构定义并且可以很好地读取数据,但是我担心我这样做会最终导致我的应用程序死机.
using (BinaryReader br = new BinaryReader(File.Open("myfile.bin", FileMode.Open)))
{
long pos = 0L;
long length = br.BaseStream.Length;
CPP_STRUCT_DEF record;
byte[] buffer = new byte[Marshal.SizeOf(typeof(CPP_STRUCT_DEF))];
GCHandle pin;
while (pos < length)
{
buffer = br.ReadBytes(buffer.Length);
pin = GCHandle.Alloc(buffer, GCHandleType.Pinned);
record = (CPP_STRUCT_DEF)Marshal.PtrToStructure(pin.AddrOfPinnedObject(), typeof(CPP_STRUCT_DEF));
pin.Free();
pos += buffer.Length;
/* Do stuff with my record */
}
}
Run Code Online (Sandbox Code Playgroud)
我认为我不需要使用GCHandle,因为我实际上并没有与C++应用程序通信,所有内容都是通过托管代码完成的,但我不知道另一种方法.
c# ×4
c++ ×2
.net ×1
c ×1
closures ×1
debugging ×1
f# ×1
generics ×1
keyboard ×1
lambda ×1
linq ×1
marshalling ×1
performance ×1
pinvoke ×1
projection ×1
scroll-lock ×1
vb.net ×1
visual-c++ ×1