相关疑难解决方法(0)

这个C++声明是什么意思?

我正在为一个类创建一个类图,该类在其头文件中有许多与此类似的定义.

  1       2                                        3             4       5
const std::pair<Controller<_Tp,_Val>*, _Val>& getHighestBidder(_Tp obj) const;
Run Code Online (Sandbox Code Playgroud)

我知道他们中的几个人做了什么,

2) says that this method will return a std::pair<Controller<_Tp, _Val>*, _Val>
3) gives the name of the function
4) defines the type of object this function accepts as a parameter
Run Code Online (Sandbox Code Playgroud)

但是,1和5是什么意思?

任何帮助/指针都会很棒.谢谢

c++

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

未定义的Base :: object链接器错误引用@ c ++ w/freeglut

我有这个代码

/////////////////////////////////////Gnome.cpp文件

 #include "Living.h"

class Gnome:public Living{
private:

public:
Gnome();
void drawObjects();
};


Gnome::Gnome()
{
spriteImg = new Sprite("graphics/gnome.bmp"); //<-------------this is where it says there is the error

loaded = true;
}
Run Code Online (Sandbox Code Playgroud)

///////////////////////////////////Living.h file

#include <iostream>

 #include "Sprite.h"


using namespace std;

class Sprite;

class Living{

protected:
int x,y;
static Sprite *spriteImg; //= NULL;
bool loaded;


void reset();


public:

Living();
~Living();
int getX();
void setX(int _x);
int getY();
void setY(int _y);
void virtual drawObjects() =0;


};
Run Code Online (Sandbox Code Playgroud)

// living.cpp

#include "Living.h"


Living::Living() …
Run Code Online (Sandbox Code Playgroud)

c++ opengl linker-errors freeglut

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

C++包含后卫似乎不起作用?

我以前曾多次使用过包括警卫,但从未真正理解他们的工作方式或原因.

以下为什么不工作?

#ifndef CAMERA_CLASS_HPP
#define CAMERA_CLASS_HPP


class camera_class
{
....
};

camera_class glcam = camera_class();


#endif // CAMERA_CLASS_HPP
Run Code Online (Sandbox Code Playgroud)

错误是这样的:(你可以从这个问题的标题中猜出它会是什么!)

-------------- Build: Debug in System ---------------

Linking console executable: bin/Debug/System
/usr/bin/ld: error: obj/Debug/main.o: multiple definition of 'glcam'
/usr/bin/ld: obj/Debug/camera_class.o: previous definition here
/usr/bin/ld: error: obj/Debug/main.glfunc.o: multiple definition of 'glcam'
/usr/bin/ld: obj/Debug/camera_class.o: previous definition here
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
Run Code Online (Sandbox Code Playgroud)

另外,有人可以向我解释为什么头部防守工作吗?

c++ header file include guard

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

在同一项目中的2个不同的c ++文件之间传递值

菜鸟问题就在这里。如何在同一项目的2个不同cpp文件之间传递值?你做物体吗?如果是,另一个cpp文件怎么看?一些启示。

编辑:一些澄清。我正在尝试将直接输入与程序连接(我有sdk插件)。我正在尝试将操纵杆与其连接。遍历代码似乎没有主要功能,但我可能错了(例如,我可能没有查看正确的文件)。我知道编程,还有指针和东西,类。为了实现我想要的东西,我应该学习或深入学习吗?

c++

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

是否没有必要定义类成员函数?

以下代码编译并运行完美,

#include <iostream>

class sam {
    public:
        void func1();
        int func2();
};

int main() {
    sam s;
}
Run Code Online (Sandbox Code Playgroud)

是否因缺少类成员定义而产生错误?

c++

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

将类更改为静态类的奇怪之处

所以我已经决定将我的类(资源管理器类)更改为c ++中的静态类,我收到了一条我无法理解的错误消息...也许你们可以帮助我?:)

继承人头文件:

#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H

#include <iostream>
#include <map>
#include <string>
#include "Image.h"

namespace sz {
    typedef std::map<std::string, sz::Image> TStrImageMap;
    typedef std::pair<std::string, sz::Image> TStrImagePair;

    class ResourceManager {
    private:
        static TStrImageMap images; // Name, Image(sz::Image)
    public:

        static void AddImage(std::string name, std::string path);
        //void AddSound();

        static sz::Image &GetImage(std::string name);
        //GetSound();
    };
}
#endif
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

1>------ Build started: Project: Basic SFML, Configuration: Debug Win32 ------
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>ResourceManager.obj : …
Run Code Online (Sandbox Code Playgroud)

c++ static map sfml

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

引用尚未定义的对象

我有两个需要指向彼此的对象......唯一的问题是,由于它们是按特定顺序声明的,因此一个或另一个不知道存在的另一个对象.例如:

...
#define foobar_h

class Foo {
  Bar* b;
};

class Bar {
  Foo* f;
};

...
Run Code Online (Sandbox Code Playgroud)

我如何声明这些类,以便他们能够快乐地引用彼此?

c++

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

C++变量由2个文件共享

我有4个文件:

  • shared.h
  • main.cpp中
  • something.h
  • something.cpp

shared.h:

#ifndef SHARED_H
#define SHARED_H

int* sth;

#endif
Run Code Online (Sandbox Code Playgroud)

something.h:

#ifndef SOMETHING_H
#define SOMETHING_H

class foo
{
   public:
      void printVar();
};

#endif
Run Code Online (Sandbox Code Playgroud)

something.cpp:

#include <iostream>
#include "something.h"
#include "shared.h"

using namespace std;

void foo::printVar()
{
    cout<<"Foo: "<<*sth<<endl;
};
Run Code Online (Sandbox Code Playgroud)

main.cpp中:

#include <cstdlib>
#include <iostream>
#include "shared.h"
#include "something.h"

using namespace std;

int main(int argc, char *argv[])
{
    sth=new int(32);

    foo x;
    cout<<"Main: "<<*sth<<endl;
    x.printVar();

    system("PAUSE");
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

编译器返回*sth的multipe定义;

我在*sth中添加了静态修饰符并编译,但崩溃了.我更改了打印以打印指针的地址,我返回了程序:

Main: 0x3e0f20
Foo: 0
Run Code Online (Sandbox Code Playgroud)

为什么没有分配foo的指针?我想在main中只分配一次,然后在其他文件中共享...我该怎么做?它是extern修饰符的东西吗? …

c++ variables share pointers class

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

未解决的外部

我正在研究一个简单的自上而下的射击游戏,并希望将我的船只移到一个单独的ShipManager类,在那里我可以从一个位置管理所有这些.但是,在启动时,我的playerShip上出现了一个链接器错误:

错误LNK2001:未解析的外部符号"public:static class Ship*ShipManager :: playerShip"

ShipManager.h如下所示:

class Ship;

class ShipManager
{
public:
static Ship*    playerShip;
};
Run Code Online (Sandbox Code Playgroud)

我在ShipManager .cpp中什么都没有.我错过了什么?我使用此代码的唯一其他地方是在我的游戏类中,我实际上正在调用ShipManager :: playerShip,我没有在那里得到任何错误.

我在我的game.cpp中包含"ShipManager.h",所以应该找到它吗?我有一种感觉,我在这堂课中忘记了一些简单的事情.

c++ linker

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

声明与C中的定义

考虑一下代码:

int main(void)
{
    int a;
}
Run Code Online (Sandbox Code Playgroud)

据我所知,这int a;是一个定义,因为它会导致存储被保留.引用C标准(N1570委员会草案 - 2011年4月12日):

6.7/5语义 声明指定了一组标识符的解释和属性.标识符的定义是该标识符的声明:

- 对于一个对象,导致为该对象保留存储;

...

问题出在这里:编译器可能会优化存储,因为我们没有使用变量.那么int a;是宣言吗?而如果我们做printf("%p", &a)main(void)-当然现在编译器必须分配存储空间,所以是声明/定义的概念依赖于你是否以后使用标识符或没有?

c language-lawyer

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