小编Tho*_*ews的帖子

从Visual Studio 2008中删除调试和发布配置

我修改了默认的Debug配置,以便输出目录类似$(SolutionDir)$(PlatformName)/$(ConfigurationName).

接下来,我创建了调试变体,DebugStatic并且DebugDll更明确地了解了正在创建的目标.我通过复制Debug配置创建了它们.

以类似的方式,我创建ReleaseDLLReleaseStatic从修改后的Release配置.

使用Configuration Manager,我删除了DebugRelease配置.

DebugRelease配置仍然在显示批生成窗口以及在配置下拉框在属性页窗口(从右键点击项目名称显示出来,然后选择属性).

如何清洁,擦除,擦除,擦除DebugRelease配置?

(Debug的模糊性导致我解决了几周的问题,特别是在X64项目中意外组合Win32调试DLL时)
(我搜索了Web和StackOverflow,但没有发现任何关于完全删除这些配置的信息.)

c++ deployment configuration visual-studio-2008 visual-studio-debugging

1
推荐指数
1
解决办法
4135
查看次数

写程序执行sum = 1+(1 + 2)+(1 + 2 + 3)+ ... +(1 + 2 ... + n)

我无法正确使用代码.有人可以帮忙吗?

#include<stdio.h>
int main()
{
 int n, sum,i,j;

 printf("Please enter an integer, n = ");
 scanf("%d", &n);

 for(i=1;i<=n;i++)
     for(j=1;j<=i;j++)
         sum = sum + n;
 printf("sum = %d", sum);


 return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
3
解决办法
5万
查看次数

MISRA违规规则10.1和枚举

首先,这类似于:如何隐式转换整数类型?但是有一个不同的MISRA警告.

编译器不会生成MISRA错误,但静态分析工具会生成错误.我有一张正在进行工具制造商的票.

鉴于:

#include <stdio.h>
enum Color {RED, VIOLET, BLUE, GREEN, YELLOW, ORANGE};

int main(void)
{
  enum Color my_color;
  my_color = BLUE;
  if (my_color == YELLOW)  // Generates MISRA violation, see below.
  {
     printf("Color is yellow.\n");
  }
  else
  {
     printf("Color is not yellow.\n");
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

静态分析工具正在为if语句生成MISRA违规:

MISRA-2004 Rule 10.1 violation: implicitly changing the signedness of an expression.
Converting "4", with underlying type "char" (8 bits, signed),
to type "unsigned int" (32 bits, unsigned) with …
Run Code Online (Sandbox Code Playgroud)

c enums misra

0
推荐指数
1
解决办法
8511
查看次数

OOP,构造函数不工作

我试图调用构造函数但它不起作用.代码是这样的:

// Event.h

class Event
{
  private:
    int Time;
    int Date;
  public:
    Event();
    Event(int t, int d)
}
Run Code Online (Sandbox Code Playgroud)

// Event.cpp

Event::Event(){}

Event::Event(int time, int date){
Time=time;
Date=date;
}
Run Code Online (Sandbox Code Playgroud)

//现在在另一个.cpp文件中我试图调用这样的构造函数:

Event eve;
eve(inputTime,inputDate); // inputTime and inputDate are inputs 4m user.
//Error is:  no match for call to â(Event) (Time&, Date&)â
Run Code Online (Sandbox Code Playgroud)

有什么建议..............

c++

0
推荐指数
1
解决办法
82
查看次数

为什么这不起作用:`int arr [size]`但是这样做`int*arr = new int [size]`?

我正在学习C++.来自Java,很多东西对我来说真的很奇怪.

在某些时候,我试图创建一个在运行时确定的大小的数组,如下所示:

int size = functionCall(argument);
int array[size];
Run Code Online (Sandbox Code Playgroud)

这编译并运行,但后来在程序中给出了非常奇怪的输出.

有人告诉我,我必须这样做:

int size = functionCall(argument);
int* array = new int[size];
Run Code Online (Sandbox Code Playgroud)

因为new允许动态分配东西,即如果我理解根据只在运行时知道的东西正确分配.

两个问题:

1-我的理解是new正确的吗?

2-为什么C++不允许我的代码的第一个版本?

c++ arrays

0
推荐指数
1
解决办法
748
查看次数

初学者 C++:为什么这个 switch 语句给我一个错误?

int menuDecision = displayMenu();

  //WHILE USER DOESN'T SELECT QUIT
while(menuDecision != 3){
/*
    if(menuDecision == 1){
        Queue myQueue;
    }
    else{
        Stack myStack;
    }
*/

    switch(menuDecision){
        case 1: Queue myQueue;
                break;
        case 2: Stack myStack;
                break;
    }

    menuDecision = displayMenu();

}
Run Code Online (Sandbox Code Playgroud)

为什么当我将上面的代码作为 switch 语句运行时会出现错误,但当我使用 if/else-if 时它会起作用?基本上,程序根据菜单中选择的内容来实例化一个对象。一旦创建了对象,就会调用构造函数,构造函数会调用另一个函数,依此类推...基本上,每次在 while 循环中都会创建一个新对象。由于我在代码中没有得到很多反馈,上述实现是否会被视为“糟糕的编程”?

谢谢!

编辑:错误是:

main.cpp:27:4: error: cannot jump from switch statement to this case label
                        case 2: Stack myStack;
                        ^
main.cpp:25:18: note: jump bypasses variable initialization
                        case 1: Queue myQueue;
Run Code Online (Sandbox Code Playgroud)

c++ switch-statement

0
推荐指数
1
解决办法
2705
查看次数

在编译时阻塞运算符 ==()

我有一个 ID-Record 类,我想阻止调用者/用户使用运算符==,因为它不明确(用户可能只想比较数据字段是否相等)。

这是我的班级:

#include <string>
#include <functional>

class ID_Record
{
  public:
    bool operator==(const ID_Record& other) const
        {  throw std::bad_function_call(); }
    unsigned int id;  // Record ID used for database.
    std::string  value;
};
Run Code Online (Sandbox Code Playgroud)

我更喜欢operator==()在编译时“阻止”,这样编译器就可以捕获它而不是在运行时捕获它。

编译器应该为此代码生成错误:

ID_Record a(6, "Tree");
ID_Record b(3, "Platinum");
if (a == b) std::cout "Records are equal\n"; // This line should fail compilation.
Run Code Online (Sandbox Code Playgroud)

我也想阻止编译器生成的功能的情况。

c++ operator-overloading runtime-compilation

0
推荐指数
1
解决办法
123
查看次数

尝试将以下代码放入c ++标头中

我正在努力将一个类似的代码串放入一个头文件中,以便多个.cpp文件可以使用bool.将此添加到我的程序后我遇到了问题并希望得到一些帮助.

这是代码:

BOOL IsUserAdmin(VOID)
{
    BOOL b;
    SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
    PSID AdministratorsGroup; 
    b = AllocateAndInitializeSid(
            &NtAuthority,
            2,
            SECURITY_BUILTIN_DOMAIN_RID,
            DOMAIN_ALIAS_RID_ADMINS,
            0, 0, 0, 0, 0, 0,
            &AdministratorsGroup); 
    if(b) 
    {
        if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) 
        {
            b = FALSE;
        } 
    FreeSid(AdministratorsGroup); 
    }

return(b);
}
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助.

c++ header

-2
推荐指数
1
解决办法
72
查看次数