header file help

if I have this in header file:

can I do this in the .cpp file?:
Last edited on
A few issues.

1. I am assuming that the cpp file is your main cpp file (with the main method in it). Because otherwise, it is hard to say. It depends on which cpp file you are talking about and what you are trying to accomplish. My bet is no... see the other issues.

2. If you ARE talking about your main method, then it depends on what you are trying to do. Are you trying to create an instance of ready queue if input = 'A' or are you trying to call the ready_queue function?

2 A: If you are trying to create an instance of ReadyQueue then you need to rename the function to be the same as the class name and remove the void type in front of it.

2 B: If you are trying to simply call the ready_queue function, you cannot call ready_queue() without having an instance of the class and referring to that class before calling its function. Like this:

1
2
3
ReadyQueue r;
if (input == 'A')
	r.ready_queue();
Last edited on
No; ready_queue() is a method and requires a ReadyQueue object in order to call it. Thinking about it, if you could just call it like that, what 'tail' would it operate on? You may want to check out this tutorial for some information about how classes work:
http://www.cplusplus.com/doc/tutorial/classes/
So I'm trying to generate PCB at the tail of the ready queue.

so basically the PID number is supposed to increase at the tail of the ready queue. but this is not seeming to work.


Last edited on
like nothing happens right now.
1
2
3
4
5
switch(input){
  if (input == 'A'){
        ready_queue.arrival();
 }
}
does this even compile? I think you want to either remove the case or change if(input == 'A') to case 'A': then remove the 2 extra curly braces {}

Anyways, are you getting any errors? You basically want to set it up like this:

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
30
31
32
33
34
//test.hpp
#ifndef TEST_HPP
#define TEST_HPP

class Test
{
    public:
        void function();
};

#endif

//test.cpp
#include "test.hpp"
#include <iostream>

void Test::function()
{
    std::cout << "Test::function() called" << std::endl;
}

//main.cpp
#include "test.hpp"
#include <iostream>

int main()
{
    std::cout << "main function called\n";

    Test t;
    std::cout << "Created Test object\n";

     t.function();
}
Last edited on
This is not incrementing the pointer.

This is my main file:
Last edited on
It is only outputting "A process with PID 1 has arrived" everytime I enter A.
Accidentally deleted post on phone but basically you don't want to increment the pointer you want to increment what is being pointed to like you are now and he reason you get 1 each time is you point to a variable with a value of 0 each time. Eight make it static or put it in a constructor
Thank you so much! So this is in my main file. My user needs an option for case c1.....c9, p1.....p9 and d1......d9. Any suggestions? Greatly appreciated!

Last edited on
From what I am understanding you would want embedded switches if you are doing different things for each letter/number.

1
2
3
4
5
6
7
8
9
switch(letter)
{
    case c:
        switch(number)
        {
            case 1:
                //do something and break
        }
}


Though if you were a little more clear there may be a better alternative solution.
could you please help me with this issue? I would greatly appreciate it!


but I get error that c is not declared in the sys_gen() function
Last edited on
How is the function declared as? It should be void PCB::sys_gen()
another problem is that my cdrw_arrival() function is not working properly, so when there are no process like if none arrived its supposed to
Last edited on
It probably has to do with the fact that line 10 and line 13 are the same exact statement.

You say if head is less than tail then do something. Which means tail is greater than or equal to head.

Then after doing that you check if tail is greater than or equal to it. Which means it is never called. You could simply use an else statement.

The same thing is happening on lines 23 and 27.
Last edited on
hmmmm its better but still not working properly.

1
2
3
if (*tail <= *head){
			cout<<"Cannot make system call for device-CPU, and therefore Ready Queue, are empty!"<< endl<<endl;
		}


This part maybe the problem.
Last edited on
I'm not sure exactly what you are trying to do since you removed your code and I worked all day...

Do you increment tail and decrement head or what?
Topic archived. No new replies allowed.