#include <iostream>
using namespace std;
void f(int& a)
{
cout << "void f(int& a)" << endl;
}
void f(const int& a)
{
cout << "void f(const int& a)" << endl;
}
int main()
{
int a = 6;
int &b = a;
const int c = 8;
f(a);
f(b);
f(c);
f(3);
return 0;
}
void f(int& a) void f(int& a) void f(const int& a) void f(const int& a)
#include <iostream>
using namespace std;
int main()
{
const int a = 1;
const int b = 2;
int array[ a + b ] = {0};
for (int i = 0; i < sizeof array / sizeof *array; i++)
{
cout << array[i] << endl;
}
}
#include <stdio.h>
int main()
{
int i;
const int a = 1;
const int b = 2;
int array[ a + b ] = {0};
for (i = 0; i < sizeof array / sizeof *array; i++)
{
printf("%d",array[i]);
}
}
c:/test1/te.c(8): error C2057: 应输入常数表达式 c:/test1/te.c(8): error C2466: 不能分配常数大小为 0 的数组
const int size;
header.h
const int test = 1;
test1.cpp
#include <iostream>
#include "header.h"
using namespace std;
int main()
{
cout << "in test1 :" << test << endl;
}
test2.cpp
#include <iostream>
#include "header.h"
using namespace std;
void print()
{
cout << "in test2:" << test << endl;
}
extern const int test = 1;
test2 error LNK2005: "int const test" (?test@@3HB) 已经在 test1.obj 中定义
header.h
const int test = 1;
test1.c
#include <stdio.h>
#include "header.h"
int main()
{
printf("in test1:%d/n",test);
}
test2.c
#include <stdio.h>
#include "header.h"
void print()
{
printf("in test2:%d/n",test);
}
错误消息:
test3 fatal error LNK1169: 找到一个或多个多重定义的符号 test3 error LNK2005: _test 已经在 test1.obj 中定义
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有