考虑一下,我有两个 Windows 独立 GUI 应用程序。每当我在第一个 GUI 中按下命令按钮时,其他 GUI 都应该捕获按钮的状态,并且应该在其中的文本框中显示 ON 或 OFF。如何使用共享内存来做到这一点。
PS:我使用的是 VC++ 2008。
下面我给出两个程序及其输出.
代码1:
#include<iostream>
using namespace std;
template <class X,class Y> X sumargs(X a,Y b)
{
cout<<"\nThe sum is :" << a+b;
}
int sumargs(int a,char b)
{
cout<<"\nThis works\n";
return 1;
}
int main()
{
sumargs<int>(1,2);
sumargs<char>(4,9.0);
sumargs<double>('d',8);
sumargs(7,'a');
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出1:
The sum is :3
The sum is :13
The sum is :108
This works
Run Code Online (Sandbox Code Playgroud)
代码2:
#include<iostream>
using namespace std;
template <class X,class Y> X sumargs(X a,Y b)
{
cout<<"\nThe sum is :" << a+b;
}
int sumargs(int …Run Code Online (Sandbox Code Playgroud) 在以下程序中,相同的内存位置如何保持不同的值?我正在使用g ++编译器.
码:
#include<iostream>
using namespace std;
int main()
{
const int i=100;
int *j = const_cast<int*>(&i);
*j=1;
cout<<"The value of i is:"<<i<<endl;
cout<<"The value j holds:"<<*j<<endl;
cout<<"The address of i is:"<<&i<<endl;
cout<<"The address of j is:"< <j<<endl;
}
Run Code Online (Sandbox Code Playgroud)
输出:
The value of i is:100
The value j holds:1
The address of i is:0xbffbe79c
The address of j is:0xbffbe79c
Run Code Online (Sandbox Code Playgroud) 为什么这个宏给出输出144而不是121?
#include<iostream>
#define SQR(x) x*x
int main()
{
int p=10;
std::cout<<SQR(++p);
}
Run Code Online (Sandbox Code Playgroud)