Very annoying "can not build" errors plus one other error.

First off I should probably say the I use Code::Blocks as my IDE and compiler.
When I run the following programs I get a message saying "this file has not been built" and ultimately it fails to compile and run my source code.
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <ctime> 
#include <cstdlib>
using namespace std;
 
int main()
{
srand(time(0));
      cout << 1+rand()%100; 
}

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
 
 
int x=10;
 
 
int main()
{
int x=1;
        cout << x;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream> 
using namespace std;
 
 
void pass_by_value(int a);
void pass_by_reference(int *a);
 
 
int main()
{
int x=13;
int y=13;
pass_by_value(x);
pass_by_reference(&y);
    cout << "x is now set to " << x << endl;
    cout << "y is now set to " << y << endl;
}
 
 
void pass_by_value(int a)
{
a=99;
}
 
 
void pass_by_reference(int *a)
{
*a=66


I'm also getting a strange "undefined reference to WinMain@16 error when I try to run these files.

main.cpp
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include "Class.h" //Remember to add this in order to access elements from your class.
using namespace std;
 
 
int main()
{
    Class c_one;
    return 0;
}

Class.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef CLASS_H
#define CLASS_H
 
 
 
 
class Class
{
    public:
        Class();
};
 
 
#endif 


Class.cpp
1
2
3
4
5
6
7
#include "Class.h"
#include <iostream>
using namespace std;
Class::Class()
{
    cout << "This is only printed when an object for this class is made.\n";
}
It doesn't say more than that? What happens if you press Compile/Build (or whatever it's called) as opposed to Run?
This code here seems to work fine:
http://cpp.sh/23sz
http://cpp.sh/3p5c
http://cpp.sh/4f6t
Your setup or how you are using Code::Blocks must be the problem. Have you tried reinstalling Code::Blocks? Also in the video I noticed that you clicked no when it asked if you wanted to build the project. You should have clicked yes. When you clicked yes there was no error. Which is expected. Try adding the line cin.get(); before return 0; in int main(). This will cause the program to wait for user input before exiting.

Why do you have 14 lines of numbers in your Class.h?

Edit: Also in the future, please do not upload code videos to youtube unless they match the resolution of your monitor. The video was really blurry. At least 720p or 1080p preferably.
Last edited on
Topic archived. No new replies allowed.