codeblocks

What is a guard block for a header file in C++?

∥☆過路亽.° 提交于 2021-02-20 11:32:21
问题 I'm trying to make a C++ class using the Code::Blocks IDE and there is a field called "Guard block." I've done a search and haven't been able to find any useful information. What is this field for? Thanks. 回答1: Guard blocks are used to protect against the inclusion of a header file multiple times by the same compilation unit (c++ file). They look something like this: // Foo.h #ifndef INCLUDE_FILE_NAME_HERE_H_ #define INCLUDE_FILE_NAME_HERE_H_ class Foo { }; #endif If you include the same file

C - Undefined reference to function error with linked files

笑着哭i 提交于 2021-02-18 18:09:30
问题 I started implementing a large program. But I ran into a massive issue. So here is very simplified code of my program. I have a separate .c file for my functions which is normal.c the main program is main.c and I have linked those two with cal.h header file. main.c #include <stdio.h> #include "cal.h" void main() { int num1, num2, ans; num1=5; num2=5; ans=add(num1, num2); printf("%d" ,ans); } normal.c #include "cal.h" int add(int num1, int num2) { return num1+num2; } cal.h #ifndef CAL_H

C error: “Undefined reference to 'sf_open'” from libsndfile

非 Y 不嫁゛ 提交于 2021-02-17 06:29:42
问题 I am using Code::Blocks to test some codes, and I just can't biuld this code: #include <stdio.h> #include <stdlib.h> #include <sndfile.h> int main() { SNDFILE *sf; sf = sf_open("file.wav",SFM_READ,&info); //error happens in this line ... And the error is "undefined reference to `sf_open'", this not only happens to sf_open but also to any function from sndfile.h. Actually here is what I did to get here: I've first downloaded and installed libsndfile for Windows x64 (I'm using Windows 10) from

How to set cin to a member function of a class in C++?

冷暖自知 提交于 2021-02-17 05:07:43
问题 I am making a small console game and I have a player class with private integers for the stats and a private string for the name. What I want to do is to ask the user for their name, and store that into the private name variable in the player class. I got an error stating: error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'void') Here is my code: main.cpp #include "Player.h" #include <iostream> #include <string> using namespace std; int main

How to set cin to a member function of a class in C++?

懵懂的女人 提交于 2021-02-17 05:05:23
问题 I am making a small console game and I have a player class with private integers for the stats and a private string for the name. What I want to do is to ask the user for their name, and store that into the private name variable in the player class. I got an error stating: error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'void') Here is my code: main.cpp #include "Player.h" #include <iostream> #include <string> using namespace std; int main

Unable to compile .f (fortran file) in codeblocks 13.12

安稳与你 提交于 2021-02-15 07:14:53
问题 I am trying to execute give fortran code in Code::Blocks on Windows 8 program main write (*,*) "hi" stop end The error I am getting is G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write' G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_transfer_character_write' G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write_done' G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_stop_string' G:

Returning a struct from function

你说的曾经没有我的故事 提交于 2021-02-08 09:49:17
问题 I'm trying to understand how to return a struct from a function but I'm completely lost. Here is the code: void initialize_server(struct data host_port){ printf(" Set IP Address (X.X.X.X): "); fgets(data.host, sizeof(data.host), stdin); strchomp(data.host); printf(" Set Port: "); fgets(data.port_inc, sizeof(data.port_inc), stdin); strchomp(data.port_inc); return data; } and heres the code from the .h struct data{ char host[16]; char port_inc[8]; }; void initialize_server(struct data host_port

error: 'x' does not name a type

China☆狼群 提交于 2021-02-07 20:54:12
问题 When I try to declare an instance of my class 'Game' I receive the compile error "error: 'Game' does not name a type" for main.cpp. If probably doesn't matter but i'm using codeblocks. Relevant code from Game.cpp #include "../include/main.h" class Game { private: public: }; Relevant code from Main.cpp #include "../include/main.h" Game g; //this is the line it is referring to int main(int argc, char* args[]) { return 0; } I'm only starting to learn c++ so i probably overlooked something

Debugging in Code::Blocks doesn't seem to work - missing debugging symbols

与世无争的帅哥 提交于 2021-02-06 11:08:42
问题 I'm trying to debug a program in Code::Blocks. I followed this guide and this short video as far as I could, but the debugger doesn't stop at breakpoints ... I saw a similar question which remained unsolved (I wasn't sure if I should bump it or open a new one with more details), I do have the "Produce debugging symbols [-g]" flag checked. Optimizations and "Strip all symbols [-s]" are also all disabled. I even tried the flag -ggdb as suggested there, no success either. I'm using TDM-GCC 4.5.2

Debugging in Code::Blocks doesn't seem to work - missing debugging symbols

戏子无情 提交于 2021-02-06 11:04:35
问题 I'm trying to debug a program in Code::Blocks. I followed this guide and this short video as far as I could, but the debugger doesn't stop at breakpoints ... I saw a similar question which remained unsolved (I wasn't sure if I should bump it or open a new one with more details), I do have the "Produce debugging symbols [-g]" flag checked. Optimizations and "Strip all symbols [-s]" are also all disabled. I even tried the flag -ggdb as suggested there, no success either. I'm using TDM-GCC 4.5.2