我正在尝试通过Visual Studio2008Express在C++中使用SDL。以下程序将进行编译,但不链接:
#include <SDL.h>
int main(int argc, char *argv[])
{
return 0;
}
链接错误是:
LINK : fatal error LNK1561: entry point must be defined
无论我如何或是否链接到SDL.lib和SDLmain.lib,我都会得到这个结果。无论是否使用extern "C",将main定义为main()或SDL_main()都会产生相同的错误。
编辑
我现在面临一个问题,即我目前正在尝试使用更新版本的ASP.NET 5 (RC1,CoreCLR)创建一个控制台应用程序,代码如下所示:
using System;
public class MyTestClass {
public static void Main(string[] args) {
Console.Write("Hello StackOverflow");
}
}
在执行dnx run时,我得到以下错误:
does not contain a static 'Main' method s
我是个新手,所以请耐心点。我目前正在学习C#和Java,它们的相似之处之一是main函数需要封装在一个类中。例如
public class HelloWorld {
public static void main(String[] args) {
// Some Code
}
}
现在我明白了,main通常是运行程序时的“入口点”。所以基本上,无论main函数在哪里,你的程序都会开始执行。但我相信在这两种语言中,你都可以在多个类中拥有多个main函数。所以,当我编译一个包含多个主函数的项目时,“入口点”在哪里?编译器如何知道从哪里开始呢?
我想知道是否可以在主函数中将命令行程序的参数直接定义为参数,如下所示:
public class HelloWorld {
public static void main(double a1, double a2) {
//do something with a1, a2...
}
}
而不是:
public class HelloWorld {
public static void main(String[] args) {
//do something with args[0], args[1]
}
}
据我所知,String args[]接受String类型的元素数组--运行时系统通过这种机制将信息传递给应用程序。
如果我们采用这样一个简单的加法程序:
class Add {
public static void main(String args[]) {
int x = 10;
int y = 30;
int c = x + y;
System.out.println(c);
}
}
显然,程序不需要任何命令行参数来计算结果。不向args数组传递任何值。那么,是否有必要包含这个数组,还是main()语法要求我
我编写了一个程序,其中有两个主method.And,我用命令提示符指定了入口点。
class Program
{
static void Main()
{
Console.WriteLine("Test");
}
}
class Test
{
static void Main()
{
Console.WriteLine("Test");
}
}
csc Program.cs /main:Test
Well.Can我用命令提示符确定入口点方法?
例如
class Program
在python中,我们可以使用参数名将参数传递给被调用的函数,比如在下面的代码中,我们如何做相同的事情-- C++,我需要这样做,因为如果我们有太多的参数,很容易弄乱被调用函数和调用函数中传递的参数的位置。
def calendar(year,month,day):
return "f{day}:{month}:{year}"
print(calendar(day=4,year=2021,month=9) #here arguments are passed in order of day,year and month
使用命名参数定义函数时,输出"4:9:
我在VC++编译器上遇到了麻烦。我已经用编译器、库和头安装了windows,并试图编译如下所示的测试程序:
#include <cstdio>
int main(int argc, char* argv[]) {
printf("%s", "Hello world!");
return 0;
}
这是我用来编译的命令行脚本:
@echo off
set clpath=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
set clname=cl.exe
s
public static void main (string[] args)是一个主要的方法,它必须给出一个字符串数组作为参数。
但是,当我运行一个程序时,main方法会自动运行,而不需要使用参数显式调用它。
因此,我有以下问题:
主要方法的论证类型重要吗?
是否存在显式调用带有参数的主方法的情况?如果是的话,这种情况的例子是什么?
class Half {
public int evaluate(int arg) {
return arg/2;
}
}
public class Box {
public static int [] main (int[] arrIn) {
int[] arrOut = new int[arrIn.length];
Half func = new Half();
for (int i=0; i< arrIn.length; i++)
arrOut[i] = fu
我期望下面的代码会出现编译器问题,但令人惊讶的是,它没有。
class p {
static int a = 10;
public static void main(String...args) {
System.out.println(a);
}
}
class child extends p {
public static void main(String[] args) {
System.out.println(p.a+10);
}
}
有人能告诉我:
( a)为什么编译器不抱怨多个main()方法?
当我从命令行执行上述程序时,我可以看到只有类p