标签: visual-c++

如何在C++中为vector创建getter和setter?

我宣称vector<test*> test1;是私人的,我想为此创建getter和setter.我试过了,

void setV(vector<test*> test1)
{
    test1 = test1;
}

vector<test*> getV()
{
    return test1;
}
Run Code Online (Sandbox Code Playgroud)

它有效,但它的工作非常奇怪.还有另一种方法吗?

谢谢

c++ visual-c++

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

在Visual C++ C4723警告描述中,"潜在除零"是什么意思?

当我在Visual C++ 10中编译以下代码时

int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
    int len = strlen( "" );
    if( len / 0 ) {
        rand();
    }
}
Run Code Online (Sandbox Code Playgroud)

编译器发出C4723警告 电位除以零.

什么是潜在的意思吗?我的C++代码清楚地说"除以len零",分裂潜力如何?

http://msdn.microsoft.com/en-us/library/8kd039eh.aspx

c++ compiler-construction compiler-warnings visual-c++

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

如何使用do modal关闭对话框

好吧,基本上我有一个MFC应用程序,其中包含许多需要循环的对话框.基本上,当您单击一个按钮转到另一个对话框时,我希望关闭上一个对话框.现在,对话框只显示在彼此的顶部.打开新对话框后,如何关闭对话框?这是一些示例代码:

void CMachine2Dlg::OnBnClickedNewmc()
{
    NameDlg Dlg;
    Dlg.DoModal()       

    }
Run Code Online (Sandbox Code Playgroud)

c++ mfc modal-dialog visual-c++

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

在C++中可以提供更好的错误报告吗?

目前,当我在Visual C++ 10中编译此代码时:

Undeclared var;
Run Code Online (Sandbox Code Playgroud)

编译器发出以下错误消息:

error C2065: 'CUndeclared' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'var'
error C2065: 'var' : undeclared identifier
Run Code Online (Sandbox Code Playgroud)

只有第一个是有用的,其余只增加输出中的噪音.现在我明白,或许产生更漂亮的错误消息并不是编译器开发的首要任务.

我想知道的是 - 是否有可能在C++中有更好的错误报告,或者C++是如此硬核,以至于编译器别无选择,只能报告三个错误?

c++ compiler-construction compiler-errors visual-c++

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

未声明的标识符

需要第二组眼睛.我收到以下错误:

1>c:\users\thom\documents\cworkspace\barnaby\barnaby\timezone.h(15): error C2065: 'TransitionTimeInfo' : undeclared identifier
Run Code Online (Sandbox Code Playgroud)

这是我收到错误的代码行:

Timezone(std::vector<LeapSecondsInfo> &leapSecondsVector, std::vector<unsigned char> &localTimeTypes, std::vector<P6::UINT8>  &stdWallIndicators, &std::vector<unsigned long> &transitionTimes, std::vector<TransitionTimeInfo> &transitionTimesInfo, std::vector<P6::UINT8> &utcLocalIndicators){
Run Code Online (Sandbox Code Playgroud)

这是我班级构造函数的行.该文件包含以下内容:

#include "stdafx.h"
Run Code Online (Sandbox Code Playgroud)

这是stdafx.h的重要部分:

#include "targetver.h"
#include "barnaby.h"
#include "LeapSecondsInfo.h"
#include "p6types.h"
#include "Timezone.h"
#include "TransitionTimeInfo.h"
Run Code Online (Sandbox Code Playgroud)

这里是TransitionTimeInfo.h:

class TransitionTimeInfo
{
public:
    TransitionTimeInfo(long gmtOffset, bool daylightSavings, unsigned int abbreviationIndex){
        setAbbreviationIndex(abbreviationIndex);
        setDaylightSavings(daylightSavings);
        setGmtOffset(gmtOffset);
    }
    virtual ~TransitionTimeInfo(void) {};

    unsigned int getAbbreviationIndex(){
        return abbreviationIndex;
    }

    void setAbbreviationIndex(unsigned int newVal){
        abbreviationIndex = newVal;
    }

    bool isDaylightSavings(){
        return daylightSavings;
    }

    void setDaylightSavings(bool newVal){ …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

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

time_t是什么意思?

根据http://www.cplusplus.com/reference/clibrary/ctime/time_t/ time_t是自UTC时间1/1/1970 UTC以来的秒数.因此,如果我按照此处记录的时间调用时间函数http://www.cplusplus.com/reference/clibrary/ctime/time/,返回的秒数是从UTC时代到现在的时间,或者是由调整后的时间.它正在运行的主机的标准时区?

而且,更重要的是,为什么没有记录?

c++ visual-c++

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

回车在c ++文件中以行结尾

我一直在阅读ISO 14882:2003.它说:

S-CHAR:
源字符集除了双引号",反斜线\,或换行字符的任何成员 转义序列
通用字符名称

现在,关于换行符,当行结尾为'\ r'时,我看到一个问题,
我写了一个小cpp程序:

#include <fstream>
#include <string>
int main()
{
    const char* program=""
        "#include <string>\n"
        "int main()\n"
        "{\n"
        "  std::string s;\n"
        "  //s=\"\r"
        "  //\r"
        "  //\r"
        "  //\r"
        "  //\";\n"
        "  s=\"\\xAE\\xfffactory\\xAE\\xffaction\";\n"
        "  return 0;\n"
        "}\n"
        ;
    std::ofstream file("file.cpp", std::ios_base::trunc);
    file << program;
    file.close();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在Windows上,file.cpp(在VS编辑器中读取)是:

#include <string>
int main()
{
  std::string s;
  //s="
  //
  //
  //
  //";
  s="\xAE\xfffactory\xAE\xffaction";
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译file.cpp时,VS触发并在第6行中出错,而不是第10行.

在Linux上,file.cpp(如emacs中所读)是:

#include <string>
int main()
{
  std::string s; …
Run Code Online (Sandbox Code Playgroud)

c++ gcc visual-c++

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

为什么"候选功能无法访问",尽管已公布

candidate function(s) not accessible在调用某些成员时遇到编译错误,尽管我将它们声明为public.当涉及来自vtk的某个类(作为返回类型或参数)并且要调用的类与调用代码不在同一个VS项目中时,我只得到错误.我也试过其他vtk类型没有运气:(

这是一些测试代码:

// A.h, in a seperate class library
#include <vtkActor.h>
public ref class A
{
public:
    A(void);

    void test1(vtkActor* actor);
    vtkActor* test2();
    void test3(char* actor);
    char* test4();
};


// B.h, Same as A but in the same project as the calling code 
#include <vtkActor.h>
ref class B
{
public:
    B(void);

    void test1(vtkActor* actor);
    vtkActor* test2();
    void test3(char* actor);
    char* test4();
};
Run Code Online (Sandbox Code Playgroud)

我试着从同一个项目中调用函数B是这样的:

// calls to class library
A^ …
Run Code Online (Sandbox Code Playgroud)

.net c++-cli vtk visual-c++

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

如何在C++中的同一个dll中获取dll位置路径?

假设我有一个名为MyDll.dll的dll

  • 它位于d:\ MyWorks\MyDll.dll [它是directshow dll]

  • 我想从MyDll代码中获取其位置的路径.

我使用了boost: FileSystem

string path = "";
boost::filesystem::path full_path( boost::filesystem::current_path() );
path =  full_path.string();
Run Code Online (Sandbox Code Playgroud)

但这给了我它的执行路径,即C:\ Windows\system32,而不是它的位置路径,即d:\ MyWorks\MyDll.dll.

如何在同一个dll中获取dll的位置?

更新:通过获取模块:

TCHAR path[2048];
  GetModuleFileName( NULL, path, 2048 );
  ostringstream file;

  file << path ;

  string const pathString =file.str();

  cout << "Path: " << pathString << endl;
Run Code Online (Sandbox Code Playgroud)

给我一个十六进制的字符串:0049EA95 ....

c++ windows dll boost visual-c++

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

像__TIME__这样的C++预处理程序指令有时不会更改/不会更新

我正在使用Visual Studio 2008 Express,我有这个日志代码:

fprintf(fp,"%s %s %s %s %d %s\n", pType, __DATE__, __TIME__, pFileName, lineNo, pMsg.c_str());
fflush(fp);
Run Code Online (Sandbox Code Playgroud)

有时,如果我不删除日志并且只是继续添加日志,__TIME__宏只会保持打印旧时间而不是当前时间.

我正在使用以下代码打开该文件

if(pfileName != NULL)
{
    fp = fopen(pfileName, "a+");
    if(fp != NULL)
        fseek(fp, 0, SEEK_END);
}
Run Code Online (Sandbox Code Playgroud)

c++ fopen visual-c++ c-preprocessor

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