我知道你不能通过以下方式在VS2010中添加一个名为"Socket"的类:
你得到:
'Socket' is a reserved class name
Run Code Online (Sandbox Code Playgroud)
所以相反,我尝试添加一个名为"Socket1"的类,删除所有出现的"1",VS似乎编译没有任何错误.这会引起任何冲突吗?或者正在使用命名空间以解决上述错误的正确方法?
所以我一直在关注一个教程,当我尝试编译以下代码时:
#include <glut.h>
#include <iostream>
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Test GLUT App");
glutDisplayFunc(render); // render
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop(); // initialization finished. start rendering
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.5, 0.2, 0.9);
glVertex2f(-0.5, -0.5);
glColor3f(0.1, 0.2, 0.5);
glVertex2f(0.0, -0.5);
glColor3f(0.3, 0.9, 0.7);
glVertex2f(0.0, 0.5);
glEnd();
glutSwapBuffers(); …Run Code Online (Sandbox Code Playgroud) 在使用Visual Studio 2008的本机C++中,如何使用const将接口传递给类成员?执行以下操作会导致此错误:
错误C2662:'IMyInterface :: PublicMember1'无法将'this'指针从'const IMyInterface'转换为'IMyInterface'
class IMyInterface
{
virtual std::wstring PublicMember1() = 0;
virtual int PublicMember2() = 0;
virtual void Update(const IMyInterface & myObject) = 0;
}
class MyClass : public IMyInterface
{
private:
std::wstring privateMember1;
int privateMember2;
public:
virtual std::wstring PublicMember1() { return privateMember1; }
virtual int PublicMember2() { return privateMember2; }
virtual void Update(const IMyInterface & myObject);
}
void MyClass::Update(const IMyInterface& myObject)
{
privateMember1 = myObject.PublicMember1();
privateMember2 = myObject.PublicMember2();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在C++ MSVS2010中编译这个程序,并得到奇怪的编译器错误,如
Error 12 error LNK1120: 1 unresolved externals C:\Users\win7vm\Documents\Visual Studio 2010\Projects\WinDemo \Debug\WinDemo.exe 1.
Run Code Online (Sandbox Code Playgroud)
我也得到了
Error 11 error LNK2019: unresolved external symbol "public: int __thiscall Dice::returnRoll(void)" (?returnRoll@Dice@@QAEHXZ) referenced in function "public: void __thiscall Dice::drawSpots(struct HDC__ *,int,int,int,int,int,int,int)" (?drawSpots@Dice@@QAEXPAUHDC__@@HHHHHHH@Z) C:\Users\win7vm\Documents\Visual Studio 2010\Projects\WinDemo \WinDemo \Debug\WinDemo.exe 1\Dice.obj
Run Code Online (Sandbox Code Playgroud)
这两者似乎都与语法无关,我并没有完全理解它们.基本上,我们的想法是让switch语句显示从另一个函数传递给该函数的值.我几乎可以肯定这是一个简单的参考/指针问题,我完全不知道了.这个类有一个标题,一个windows.h(开箱即用的未修改,所以你可以在需要的时候查找它),以及带有主文件的函数(这里包含的函数和类).让我预先回答几乎肯定会出现的两个问题:a)是的,它绝对必须在c ++中使用windows.h文件.b)是的,我知道有一百个更好的库和语言用于这个问题,我在这里没有选择.有人也可能试图指出声明的全局变量.在对相对较短的代码块进行故障排除时,全局变量是暂时但必要的不便.我意识到你们中的许多人都非常擅长C++,但我要求你们耐心地用我的低级C++编程来解释你的答案.谢谢.:)
**//头文件
#include <windows.h>
#include <math.h>
#include <vector>
using namespace std;
int count=0;
int *result = &count;
class Dice
{
public:
void drawSpots(HDC hdc, int x1,int y1, int x2,int y2, int r, int g,int b);
int …Run Code Online (Sandbox Code Playgroud) Windows下的程序需要管理员权限才能在用户启动时获得用户的权限.并且他们也可以通过右键单击EXE并选择"以管理员身份运行"来管理员权限运行.但是,在EXE开始之前,会出现一个消息框.这真的很恶心.
现在我希望我的应用程序以管理员身份运行,当用户单击EXE文件时,我不想要弹出消息框.
现在我想知道AdjustTokenPrivileges函数是否可以帮助我实现这一目标.
任何人都可以帮助我吗?
我已将som信息放入stringstream ss:
stringstream ss (stringstream::in | stringstream::out);
ss<<"abc 456 ";
ss<<123
Run Code Online (Sandbox Code Playgroud)
然后我决定将字符串内容检索到字符串g:
std::string s;
std::string g;
for (int n=0; n<c; n++)
{
ss >> s;
g=g+s;
}
cout << g <<endl;
Run Code Online (Sandbox Code Playgroud)
出于这个原因,我需要知道对ss进行了多少次放置.怎么知道?检索字符串信息的方法可能不是很聪明 - 然后给你自己的方式.
我知道标题有点模糊,但我现在想不出更好的标题.我的代码中的摘录如下所示:
#include<iostream>
#include<fstream>
int main(){
ifstream f("cuvinte.txt");
f.getline(cuvant);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我想阅读"cuvinte.txt"中的下一个单词时,我写了f.getline(cuvant); 但我得到以下错误
error C2661: 'std::basic_istream<_Elem,_Traits>::getline' : no overloaded function takes 1 arguments
Run Code Online (Sandbox Code Playgroud)
我不知道问题是什么,我不久前偶然发现了这个问题,仍然无法超越它.
这会崩溃:
try
{
if(1)
throw;
}
catch(...)
{
printf("hi");
}
Run Code Online (Sandbox Code Playgroud)
我以为我能做到,但我猜不是.当您不需要任何信息时,正确的投掷方式是什么?
当我使用变量参数时,它适用于int和double,但是当涉及到float时,会发生错误.
这是代码.
void vaParamTest(int a, ...)
{
va_list ap;
va_start(ap, a);
for (int i = 0; i < a; i++)
printf("%f\t", va_arg(ap, float));
putchar('\n');
va_end(ap);
}
Run Code Online (Sandbox Code Playgroud)
我传递这样的参数.
vaParamTest(3, 3.5f, 8.3f, 5.1f);
Run Code Online (Sandbox Code Playgroud) conv.h
class Base
{
public:
void foo();
};
class Derived: public Base
{
public:
void bar();
};
class A {};
class B
{
public:
void koko();
};
Run Code Online (Sandbox Code Playgroud)
conv.cpp
void Base::foo()
{
cout<<"stamm";
}
void Derived::bar()
{
cout<<"bar shoudn't work"<<endl;
}
void B::koko()
{
cout<<"koko shoudn't work"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include "conv.h"
#include <iostream>
int main()
{
Base * a = new Base;
Derived * b = static_cast<Derived*>(a);
b->bar();
Derived * c = reinterpret_cast<Derived*>(a);
c->bar();
A* s1 = new A;
B* s2 …Run Code Online (Sandbox Code Playgroud) c++ ×10
visual-c++ ×10
windows ×2
c ×1
c++11 ×1
exception ×1
mfc ×1
namespaces ×1
opengl ×1
std ×1
stringstream ×1
try-catch ×1
using ×1