結果にcharシーケンスを持つ関数を宣言するにはどうすればよいですか?
私は今これを持っています:
#define _MAX_PATH 260
char * GetTempFileName(char fileName [_MAX_PATH]);
ただし、結果は char [_MAX_PATH] 型にする必要があります。
#include <array>
typedef std::array<char,_MAX_PATH> Path;
extern class Setts
{
char path [_MAX_PATH];
public:
Setts();~Setts();
Path getTempFileName(const Path &fileName);
} setts;
Setts::~Setts(){}
Path Setts::getTempFileName(const Path &fileName)
{
GetCurrentDirectory(_MAX_PATH, path);
strcat(path, "\\");
strcat(path, fileName);
return path;
}
これが私に問題を引き起こすものです...
error C2143: syntax error : missing ';' before 'Setts::GetTempFileNameA'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2556: 'int Setts::GetTempFileNameA(Setts::Path)' : overloaded function differs only by return type from 'Setts::Path Setts::GetTempFileNameA(Setts::Path)'
char シーケンス char [_MAX_PATH] で結果を取得することは本当に不可能ですか? ここでの問題は、新しいタイプのパスを作成すると、char [_MAX_PATH] タイプに依存する条件のすべての関数がプロジェクトでエラーを引き起こすことです。
g-makulik のコメントから
path.data() ... data が何らかの関数のように見えることを意味しますが、これは何をしますか? 関数の結果がパス変数に保存された後に評価されますか? – user1141649 16分前
g-マクリック:
It provides access to the std::array's underlying data (an array of char[260]). You can use it in other places to interface that array as well. –
プロジェクトの残りの部分との互換性があるため、単純化しようとしました。
settings.h:
#include <stdlib.h>
#include <iostream>
#include <array>
typedef char Path [_MAX_PATH];
extern class Setts
{
Path& path;
public:
Setts();~Setts();
Path& getTempFileName(const Path &fileName);
bool load();
Path& BasePath;
Path& ScenPath;
Path& TempPath;
#define DEL_TEMP_ON_EXIT 1;
Path& logname;
bool intense;
} setts;
設定.cpp:
#include <windows.h>
#include "settings.h"
#include <stdio.h>
Setts::~Setts(){}
Path& Setts::getTempFileName(const Path &fileName)
{
GetCurrentDirectory(_MAX_PATH, path);
strcat(path, "\\");
strcat(path, fileName);
return path;
}
bool Setts::load()
{
TempPath = getTempFileName("scendata.tmp");
logname = getTempFileName("ats_cache.log");
return (result == ERROR_SUCCESS);
}
今、私はエラーを受け取りました:near TempPath = getTempFileName("scendata.tmp");
そしてlogname = getTempFileName("ats_cache.log");
:
'Setts::getTempFileName' : パラメーター 1 を 'const char [13]' から 'const Path (&)'に変換できません 理由: 'const char [13]' から 'const Path' に変換できませ ん コンテキストがありませんエラー C2664: 'Setts::getTempFileName' : パラメーター 1 を 'const char [14]' から 'const Path (&)'に変換できません理由: 'const char [14]' から 'const Path に変換できません' この変換が可能なコンテキストはありません