小编Gar*_*365的帖子

错误:不完整类型的无效使用

我遇到以下问题,有人有好主意吗?

\n\n
class Vector_2d;\n\nnamespace Utils {\n\nclass Align_vector : public Vector_2d {\nprotected:\n    bool check_range(int x, int y);\n\npublic:\n    enum alignment {left, right, up, down};\n\n    Align_vector(Alignment alignment);\n    void set_alignment(Alignment alignment);\n    Alignment get_alignment();\n\n};\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

错误是:

\n\n
\n

错误:无效使用不完整类型 \xe2\x80\x98class Vector_2d\xe2\x80\x99

\n
\n\n

但怎么会出现错误呢?

\n

c++ inheritance

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

为什么在这里调用复制构造函数?

#include <iostream>
using namespace std;
class A
{
    int x;
public:

    A(int a)
    {   
        x = a;
        cout << "CTOR CALLED";
    }
    A(A &t)
    {
        cout << "COPY CTOR CALLED";
    }
    void display()
    {
        cout << "Random stuff";
    }
    A operator = (A &d)
    {   
        d.x = x;
        cout << "Assignment operator called";
        return *this;
    }
};

int main()
{
    A a(3), b(4);
    a = b;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

此代码的输出是:

CTOR CALLED
CTOR CALLED
分配操作员称为
COPY CTOR CALLED

当我在visual studio中使用手表时,它表明即使在调用重载赋值运算符之前, …

c++ visual-c++ c++11 c++14

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

如何在if语句中指定单引号?

if(ch == ''')
{
   word_len++;
}
Run Code Online (Sandbox Code Playgroud)

如何指定何时ch等于'它添加一个word_len?似乎我只能使用上面的代码来指定它.

c if-statement format-specifiers

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

内联函数的链接器未解析的外部符号

我正在使用 Visual Studio 2015 开发 C++ 解决方案。

我有一个带有此声明的 cpp 源文件和头文件 hpp。

标题:

#ifndef MyLib__FREEFUNCTIONS__INCLUDE__
#define MyLib__FREEFUNCTIONS__INCLUDE__

#include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

// Check if 'str' is null, empty or consists only of white-space characters. 
inline bool IsNullOrWhiteSpace(string str);

// More functions
[ ... ]

#endif
Run Code Online (Sandbox Code Playgroud)

和源代码:

#include "FreeFunctions.h"

inline bool IsNullOrWhiteSpace(string str)
{
    return (str.empty() || (str.find_first_not_of(' ') == string::npos));
}
Run Code Online (Sandbox Code Playgroud)

我在一个类中使用这个函数:

#include "ConvertToOwnFormat.h"
#include "FreeFunctions.h"

ConvertToOwnFormat::ConvertToOwnFormat()
{
}


ConvertToOwnFormat::~ConvertToOwnFormat()
{
}

vector<Entry> ConvertToOwnFormat::ReadCatalogue(string …
Run Code Online (Sandbox Code Playgroud)

c++

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

克隆void*指向int的指针

我有一个函数的签名:

void* cloneInt(const void* i);
Run Code Online (Sandbox Code Playgroud)

int代表哈希函数的关键.我需要有这个克隆函数,因为它在我的API中用于散列表的泛型实现(此函数是int实现的一部分,此函数将作为指向我的泛型实现将使用的函数的指针转发) .但我有一个问题的理解:你怎么克隆一个int?我需要返回一个指针,该指针指向相同的值int,但内存中的位置不同.这让我非常困惑.

c pointers clone

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

Symfony2使用SoapClient

我有一个symfony2项目,它会严重抛出此错误

$c = new \SoapClient($objWidget->getLink() . '/ws.php?wsdl');
Run Code Online (Sandbox Code Playgroud)

$objwidget 不是空的,这是错误

未捕获的PHP异常Symfony\Component\Debug\Exception\ClassNotFoundException:"尝试从全局命名空间加载类"SoapClient".您是否忘记了"使用"语句?"

我试过SoapClient在顶部使用,但仍然问题SoapClient.

soap symfony

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

将int数组转换为c ++中int的向量

我有一个像这样的数组

int A[] = {1, 2, 3, 4, 5, 6, 7}
vector<int> vec;
int index = 0;
for(int i = 0; i < A.size(); i++) {
if(some condition) {
    index = i;
}
**vec(A + index, i);**
}
Run Code Online (Sandbox Code Playgroud)

如何将数组转换为从特定索引开始的向量,如上所述?

c++ arrays vector

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

类对象的新数组指针

我希望该类OUT包含一个IN指针数组.有多少是未知的.这就是我到目前为止所拥有的.

class OUT{
    class IN{/**/};
    IN** IN_handle;
    int m_size_in;
    OUT(int size_in):m_size_in(size_in){
        IN_handle = new *IN[size_in];
    }
    ~OUT(){
        for(int i=0; i<m_size_in; i++){
            delete IN_handle[i];
        }
        delete IN_handle;
    }
};
Run Code Online (Sandbox Code Playgroud)

编译说:

在赋值中不能将'int**'转换为'OUT :: IN**'

c++ arrays class

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

CRC-16 0x8005多项式,从C到C#.SOS

我有这个C代码块,我不能为我的生活理解.我需要为我发送给该方法的某个字节数组计算CRC-16,它应该给出msb(最高有效字节)和lsb(最低有效字节).我还获得了一个C编写的应用程序来测试一些功能,该应用程序还为我提供了发送内容和通过COM端口接收的内容的日志.

有点奇怪的是,我输入了我在日志中找到的这个在线计算器的十六进制字符串,但它给了我不同的结果.

我把这个方法翻译成C#,但我不明白某些方面:

  1. 什么是pucPTR在那里做(它不是在其他地方使用)?
  2. 2行代码是什么意思,第一行是什么?
  3. 为什么在第二个短的"i"是<= 7,不应该<= 8?
  4. if语句中的最后一行意味着usCRC实际上是ushort 8005?

这是代码块:

unsigned short CalculateCRC(unsigned char* a_szBufuer, short a_sBufferLen)
{
    unsigned short usCRC = 0;
    for (short j = 0; j < a_sBufferLen; j++)
    {
        unsigned char* pucPtr = (unsigned char*)&usCRC;
        *(pucPtr + 1) = *(pucPtr + 1) ^ *a_szBufuer++;
        for (short i = 0; i <= 7; i++)
        {
            if (usCRC & ((short)0x8000))
            {
                usCRC = usCRC << 1;
                usCRC = usCRC ^ ((ushort)0x8005);
            }
            else
                usCRC = …
Run Code Online (Sandbox Code Playgroud)

c c# crc

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

如何处理大括号?

这是我的问题:

在css

table{
    position:absolute;
    top:-100px;
    left:90px;
    margin:300px;
    background-color:#000000;
    a:link {text-decoration:none;}
    a:visited {text-decoration:none;}
    a:hover {background-color:Green;}
    a:active {text-decoration:underline;}
}
Run Code Online (Sandbox Code Playgroud)

{旁边table}标记被标记封闭,标记是在底部和底部的支撑标记的末端a:link {text-decoration:none;}和开口支撑标记变得无用.{a:link}

如何将第一个和最后一个{ }标记相互连接?(不是a:link {text-decoration:none;}这条线的支撑)

html html5 curly-braces

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

2个签名短签

我有两个char值char_1char_2.现在我想将它们组合成一个16位有符号整数值,其中char_1包含MSB中的符号.

| SGN | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |

| 签署字符1 | 其余的Char 1 | Char 2 |

我的尝试是:

signed short s = (((int)char_1) << 8) & (int)char_2;
Run Code Online (Sandbox Code Playgroud)

现在我得到0 s...

c++ signed integer char

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

格式化字符串c ++

我是c ++的新手,每次循环运行时都找不到如何设置不同的文件名.我想在每次循环运行时创建一个新文件,当然我必须给它们不同的文件名.否则,同一文件只是更新.在Python中,它可以很容易地完成

for i in range(10):
    filename = "myfile%f.dat" % i
Run Code Online (Sandbox Code Playgroud)

但我在c ++中找不到类似的语法.我希望有人可以帮助我,我在下面制作了一个示例脚本(使用Python语法格式化字符串),这有望使我更清楚我正在尝试做什么.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main ()
{
    for(int i = 1; i < 11; i += 1)
    {
        string filename; filename = "table%d.dat"%i;
        ofstream infile;
        infile.open( filename.c_str());
        infile << "multiplication table for " << i << endl;
        for(int j = 1; j < 11; j+=1)
        {
            infile << j*i << endl;
        }
        infile.close();
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ for-loop string-formatting

-3
推荐指数
1
解决办法
465
查看次数