我正在编写一个简单的数据结构库,同时遇到了一些问题。
我写了三个文件。collections.h是头文件,collections.cpp是实现头文件中声明的方法,main.cpp是用于测试。但编译出现错误:
对 List::GetCount() const 的未定义引用;
对 List::IsEmpty() const 的未定义引用;
对 List::Add(int) 的未定义引用;
...// 等等。
我在下面提供了我的代码,问题出在哪里?
集合.h:
#ifndef COLLECTIONS_H
#define COLLECTIONS_H
#include <windows.h>
#include <stdexcept>
template<typename T>
class ISequenceList
{
protected:
ISequenceList() { }
public:
virtual int GetCount() const = 0;
virtual bool IsEmpty() const = 0;
virtual void Add(T item) = 0;
virtual void AddRange(const T *items, int length) = 0;
virtual T &ElementAt(int index);
virtual bool InsertAt(T item, int index);
virtual bool Remove(T item) = 0;
virtual bool …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译一个项目,但收到此错误:
1>project.obj : error LNK2019: unresolved external symbol __snprintf referenced in function "unsigned char * __cdecl GetResource(char *,unsigned long &)" (?GetResource@@YAPAEPADAAK@Z)
1>Release/file.bin : fatal error LNK1120: 1 unresolved externals
Run Code Online (Sandbox Code Playgroud)
我正在使用 VC++ 2010,也尝试使用 CodeBlocks 进行编译,但出现类似的错误:
windres.exe -J rc -O coff -i C:\Users\x\Desktop\project\project\File.rc -o .objs\File.res
windres.exe: no resources
Process terminated with status 1 (0 minutes, 0 seconds)
Run Code Online (Sandbox Code Playgroud)
我的项目目录中有 File.rc 但它是 0kb,我不知道如何解决这个问题。
我很确定这与代码中的某些内容无关,因此我没有发布示例,但如果您需要示例,我会发布它。
我正在尝试调试代码块中的头文件。我尝试了一些选项,例如“运行到光标”并在头文件中放置断点,但它不会在那里停止并通过那里。如何调试其中的 .h 文件?如果您需要任何信息,请发表评论。我会提供信息。
我创建了一个名为 Test Lib 的 DLL 项目:
// main.h
#ifndef __MAIN_H__
#define __MAIN_H__
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
extern "C" {
DLL_EXPORT void print();
}
#endif
// main.cpp
#include "main.h"
#include <iostream>
#define BUILD_DLL
using std::cout;
using std::endl;
extern "C" {
DLL_EXPORT void print() {
cout << "Success" << endl;
return;
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码来自我在网上找到的一个我可以理解的示例。当我尝试编译和/或构建它时,我收到以下错误和警告:
error: function 'void print()' definition is marked dllimport
In function 'void print()':
warning: 'void print()' redeclared without dllimport attribute: previous dllimport ignored …Run Code Online (Sandbox Code Playgroud) 我现在正在练习 C 编程,并且制作了一些 BMI 计算器。它工作得很好,但是当用户在第一个输入字符串或字符时scanf将数据发送到浮点变量 'weight' 。scanf之后一切都过去了,并向我显示错误Your BMI is 1.#J。如何解决这个错误?这是我的代码。
#include <stdio.h>
int main()
{
float weight;
float height;
float result;
float c_height;
printf("Enter your weight as kilogram...\n\n> ");
scanf("%f",&weight);
//If user input char or string , it passed all thing and showed error.
printf("\nEnter your height as centimetres...\n\n> ");
scanf("%f",&height);
c_height=(height/100)*(height/100);
result=weight/c_height;
if(result<18.50)
{
printf("\nYour BMI is %.2f\n\n",result);
printf("You are underweight! Try to eat more frequently\n\n");
printf("Thank you for using my program!\n\n");
}else …Run Code Online (Sandbox Code Playgroud) 我将 Code::Blocks 与一个简单的应用程序一起使用。我有一个向量 a,其中包含三个整数 {1, 2, 3}。我添加了“a”变量来观看,但我看不到它的内容。在监视中,我右键单击 a 并选择属性,然后选中“监视为数组”框。我还点击了更新。使用值初始化向量后,程序将停止。我还从手表中删除了变量并再次添加了它。有没有办法查看a的内容?我已经检查了几乎相同问题的答案“如何在代码块中调试时查看数组的内容?” 但这没有帮助。
我正在使用代码块,我的编译器设置是[-std=c++0x]. 我使用以下代码创建了一个简单的项目:
主程序
#include <iostream>
#include "Cat.h"
using namespace std;
int main() {
Cat action;
action.meow();
action.jump();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
猫.h
#ifndef CAT_H_INCLUDED
#define CAT_H_INCLUDED
class Cat {
public:
void meow();
void jump();
};
#endif // CAT_H_INCLUDED
Run Code Online (Sandbox Code Playgroud)
CatProcess.cpp
#include <iostream>
#include "Cat.h"
using namespace std;
void Cat::meow() {
cout << "meow" << endl;
}
void Cat::jump() {
cout <<"jump" << endl;
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
当我构建并运行整个项目时,这个错误出现在我的 IDE 的 main.cpp 第 8 行:
对“Cat::meow()”的未定义引用
当我构建并运行时CatProcess.cpp,出现此错误:
错误:找不到文件的目标
构建日志:
mingw32-g++.exe -Wall …
我正在制作一个小型控制台游戏,我有一个player类,其中包含用于统计数据的私有整数和用于名称的私有字符串。我想要做的是向用户询问他们的姓名,并将其存储到类中的私有name变量中player。我收到一个错误说明:
error: no match for 'operator>>'
(operand types are 'std::istream {aka std::basic_istream<char>}' and 'void')
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
主程序
#include "Player.h"
#include <iostream>
#include <string>
using namespace std;
int main() {
Player the_player;
string name;
cout << "You wake up in a cold sweat. Do you not remember anything \n";
cout << "Do you remember your name? \n";
cin >> the_player.setName(name);
cout << "Your name is: " << the_player.getName() << "?\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
播放器.h
#ifndef PLAYER_H …Run Code Online (Sandbox Code Playgroud) 我刚刚创建了这个新类:
//------------------------------------------------------------------------------
#ifndef MULTITHREADEDVECTOR_H
#define MULTITHREADEDVECTOR_H
//------------------------------------------------------------------------------
#include <vector>
#include <GL/GLFW.h>
//------------------------------------------------------------------------------
template<class T>
class MultithreadedVector {
public:
MultithreadedVector();
void push_back(T data);
void erase(typename std::vector<T>::iterator it);
std::vector<T> get_container();
private:
std::vector<T> container_;
GLFWmutex th_mutex_;
};
//------------------------------------------------------------------------------
#endif // MULTITHREADEDVECTOR_H_INCLUDED
//------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
类的定义:
//------------------------------------------------------------------------------
#include "MultithreadedVector.h"
//------------------------------------------------------------------------------
using namespace std;
//------------------------------------------------------------------------------
template<class T>
MultithreadedVector<T>::MultithreadedVector() {
th_mutex_ = glfwCreateMutex();
}
template<class T>
void MultithreadedVector<T>::push_back(T data) {
glfwLockMutex(th_mutex_);
container_.push_back(data);
glfwUnlockMutex(th_mutex_);
}
template<class T>
void MultithreadedVector<T>::erase(typename vector<T>::iterator it) {
glfwLockMutex(th_mutex_);
container_.erase(it);
glfwUnlockMutex(th_mutex_);
}
template<class T>
vector<T> …Run Code Online (Sandbox Code Playgroud) 我有一个问题,我正在使用过剩(openGL实用工具包).我正在主窗口制作一个子窗口.主窗口显示一个简单的图形,子窗口显示另一个视图中的图形.该图旋转,因此应始终重新显示主窗口和子窗口.
但是这两个中只有一个显示旋转的数字.因此,当我启动程序时,主窗口中的图形旋转但在子窗口中它不旋转,它只是静止不动.
当我在子窗口中移动鼠标并按任意键时,角色会发生变化,因此图形在子窗口中旋转并在主窗口中静止不动.
如何让它们同时显示.我按照灯塔的教程,但它没有给我一个答案.我必须对我的视口做些什么吗?
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#include <windows.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h> …Run Code Online (Sandbox Code Playgroud)