Author Topic: Two questions from an absolute beginner..  (Read 3856 times)

Offline LadyoftheCave

  • Single posting newcomer
  • *
  • Posts: 3
Two questions from an absolute beginner..
« on: March 18, 2018, 11:29:25 am »
Goodmorning all.

I am following an udemy c++ course. I have reached lesson 31 and in this lesson the first steps of working with functions/headers and classes is explained. I am following the same steps as the person in the video (he is using eclipse). But for some reason it is not working the same in Code blocks. (I am using Code blocks 16.01)

Two problems that I encounter are:

1) The person in the video is using eclipse. In eclipse it is probably very simple to change the name of the main.cpp. I have tried everything but I cannot change this file. In help files I always find the same solution. Go to the file in the management window and then right-click on the main.cpp file then there would be an option to rename the file.. But not in this version of code-blocks. So is there a way to change this file easily?

2) The second problem is that I have created a second .cpp file in the same project and I was told that the mainfile would then automatically find the second .cpp file. But it doesn't. I have to include the second .cpp file into the main.cpp file otherwise I receive an error. I have read somewhere that you never should include a second .cpp file, so do you know how I can solve this?



Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Two questions from an absolute beginner..
« Reply #1 on: March 18, 2018, 11:46:25 am »
1. If the file is opened in the editor you cannot rename it, you have to close the file first.
2. What is the actual error? Post the full build log.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LadyoftheCave

  • Single posting newcomer
  • *
  • Posts: 3
Re: Two questions from an absolute beginner..
« Reply #2 on: March 18, 2018, 12:25:06 pm »
1) aha, of course, that sounds very logical..

2) This is the code into the main.cpp file when it is NOT working:
#include <iostream>

#include "Cat.h"

using namespace std;

int main()
{

Cat cat1;

cat1.speak();
cat1.jump();

    return 0;
}

Then I receive the following error log:

line 14: undifined reference to Cat::speak()'
line 14: undifined reference to Cat::jump()'
error: 1d returned 1 exit status
build failed: 3 errors , 0 warnings,

When I place the include to the cat.cpp:

#include <iostream>
#include "Cat.cpp"
#include "Cat.h"

using namespace std;



int main()
{

Cat cat1;

cat1.speak();
cat1.jump();

    return 0;
}
Then it is working... So I am really curious why main.cpp cannot find Cat.cpp automatically

« Last Edit: March 18, 2018, 12:28:11 pm by LadyoftheCave »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Two questions from an absolute beginner..
« Reply #3 on: March 18, 2018, 01:34:57 pm »
If a log is requested ALWAYS use the build log tab and make a fresh rebuild: Build->Rebuild or Build->Clean and Build->Build (also described here: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)

This error message is a result that your cat.cpp is not compiled. If it is not compiled this means codeblocks does not know about this file, or you have told codeblocks to not build it.
For the first: You have to add the file cat.cpp to you project with Project->Add files. Then a dialog will ask you if you want to add this file to a build target (normally all are selected and you can klick ok). You should see your file now in the project tree.
For the second: you have not selected both targets in the pop up dialog if you create or add the file... To fix this: Right click on the file->Properties->Build->Make sure all ticks are set.

I am not in the mood to describe what build targets are... You can read here: http://wiki.codeblocks.org/index.php/The_build_process_of_Code::Blocks
This might also interest you: http://wiki.codeblocks.org/index.php/Creating_a_new_project

EDIT: Also if you post code or logs use code tags (the # symbol) in the post editor...

Offline LadyoftheCave

  • Single posting newcomer
  • *
  • Posts: 3
Re: Two questions from an absolute beginner..
« Reply #4 on: March 18, 2018, 02:10:56 pm »
Hi BlueHazzard,

Thank you so much for your help, although the file was into the project, it wasn't really added to the project :-[, so thanks to you everything works now..  ;D ;D

I wish you a great sunday..


Offline bobsadino

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Two questions from an absolute beginner..
« Reply #5 on: April 20, 2018, 04:45:43 pm »
yea, u need to include it on cpp not add the cpp file into project. It's not enough

also if you make a header file make sure to write

#ifndef YOURTITLE_H
#define YOURTITLE_H

to avoid duplication on a complex project

I really like codeblocks. It's fast and lightweight. Anyone knows how to integrate MSVC 14 compiler with it?

I want to use thread(); func. I need C++ 11.  :(

since VS so slow even tho there is enough RAM.

u can kontak da kommander's discord: automator#9969

Thank
« Last Edit: April 20, 2018, 04:53:56 pm by bobsadino »