template<> 37 Junior Poster

Perhaps try something like below...

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int start;
    int end;

    cout << " Time Clock Program" << endl;

    cout << "Enter Start time (hh:mm A/P): ";
    cin >> start;

    cout << std::endl << "Enter Stop time (hh:mm A/P): ";
    cin >> end;

    cout << std::endl << "start=[" << start << "] end=[" << end << "]" << std::endl;

    return 0;
}
template<> 37 Junior Poster

It appears linker is not seeing the definitions for Client. Is Client.cpp compiled and linked with application?

template<> 37 Junior Poster
struct Point;                       // forward reference
struct MyClass1{Point &p;}; // reference to Point (ok)
struct MyClass2{Point *p;};  // pointer to Point (ok)
strcut MyClass3{Point  p;};  // Pointer Object (compile error)

Forward reference are used to inform the compiler a name is valid and defined somewhere else. However if the size of the object is required or any of the methods are used, then the actual definition is required.

No difference in runtime performance although using forward reference may reduce compile time in some cases since the header files is not required.

template<> 37 Junior Poster

How is items defined?

template<> 37 Junior Poster

It seems like the linker thinks there is no int main() function..., what does you main look like?

template<> 37 Junior Poster
///
/// below is pseudocode/pattern on a possible way to
/// start a pool of thread and end them gracefully
/// need thread and conditon variable implementation
///

#include <iostream>
#include <vector>
///
/// replace with your thread class
///
class Thread
{
public:
	virtual ~Thread(){;}
protected:	
	virtual void run() = 0;
};

///
/// worker thread to do actual work
///
class Worker : public Thread
{
public:
	Worker(size_t who_)
	:_isAlive(false)
	,_who(who_)
	{}
	 /// start thread
	 void start()
	 {
	 	_isAlive = true;
		// start your thread;
	 }
	 /// main call worker to end
	 /// and waits for worker to end
	 void end()
	 {
		_isAlive = false;
		// _event.wait();
	 }
private:	 
	 // thread enters here
	 virtual void run()
	 {
	 	std::cout << "thread who=[" << _who << "] is starting" << std::endl;;

		while(_isAlive)
		{
			// do work
		}

	 	std::cout << "thread who=[" << _who << "] is ending" << std::endl;;

		// signal thread is done
		//_event.signal();
	 }
private:
	size_t _who;
	bool _isAlive;
	// condition _event;
};

int main()
{
	std::cout << "starting main thread" << std::endl;

	const size_t MAX_POOL = 8;
	std::vector<Worker *> pool;
	for(size_t i=0; i < MAX_POOL; i++ )
	{
		Worker *w = new Worker(i);
		pool.push_back(w);
		w->start();
	}

	// wait for condition to end threads


	// tell each worker to end
	for(size_t i=0; i < MAX_POOL; i++)
	{
		pool[i]->end();
	}

	std::cout << "main thread is done" << std::endl;
}
template<> 37 Junior Poster

Have you tried google? eight queen problem c++ recursion

Lots of information on the classic problem, below are some..

http://wn.com/eight_queens_problem

http://en.wikipedia.org/wiki/Eight_queens_puzzle

http://people.moreheadstate.edu/fs/d.chatham/dlxMCCC.pdf

template<> 37 Junior Poster

simple sample of fourvector containing a threevector

class threevector
{
public:
    threevector(double a_, double b_, double c_)
    :_a(a_)
    ,_b(b_)
    ,_c(c_)
    {
    }
    threevector(const threevector &val_)
    :_a(val_._a)
    ,_b(val_._b)
    ,_c(val_._c)
    {
    }
private:
    double _a;
    double _b;
    double _c;
};

class fourvector
{
public:
    fourvector(double forth_, threevector three_vector_)
    :three(three_vector_)
    ,forth(forth_)
    {
    }
private:
    threevector three;
    double forth;
};

int main()
{
    threevector three(1.0,2.0,3.0);
    fourvector(4.0,three);
    return 1;
}
template<> 37 Junior Poster

An alternative is to have the push return true/false...

template<int MAX_SIZE>
class Stack
{
public:
    Stack()
    :_count(0)
    {
    }
    bool push(int val)
    {
        if( _count < MAX_SIZE )
        {
            _array[_count++] = val;
            return true;
        }

        return false;
    }
private:
    int _count;
    int _array[MAX_SIZE];
};
WaltP commented: While true, not acceptable. Please read the last part of the original post. +15
template<> 37 Junior Poster

do you have a class threevector?

most probably fourvector contains the threevector member variable

fourvector constructor is initializing the three vector constructor

template<> 37 Junior Poster

Without having code that compiles...

The signature may be incorrect. void insertNode(T);

Seems like you want to insert a node, not a type, which is represented by T?

template<> 37 Junior Poster

Interesting problem. Below is a small sample of the problem and fix. Seems like you need to Llist<T>::. http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html

template <class T>
class Llist
{
public:
    Llist(){;}
    void remove_head()
    {
    }
private:
    T foo;
};

template <class T>
class Stack :  public Llist<T>
{
public:
    Stack(){}
    void pop()
    {
         //remove_head();
        Llist<T>::remove_head();
    }
};

int main()
{
    return 1;
}
template<> 37 Junior Poster

Where is Node defined?

template<> 37 Junior Poster

Some windows synchronization objects, its usually best to use c++ wrappers with these (google for more information)

http://msdn.microsoft.com/en-us/library/ms685129(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/ms682411(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/ms682530(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/ms682396(v=vs.85).aspx

template<> 37 Junior Poster

Instead of timing how long it takes to run qsort sort once, execute qsort n times in a loop and see how long that takes. Vary n, until you get a reasonalble time.


// startTime;

for (size_t i=0 i < 100000; i++ )
{
qsort();
}

// endTime

template<> 37 Junior Poster

If you don’t initialize your variables, you will get garbage...
garbage in this case is any value that int is capable of representing...

template<> 37 Junior Poster

Its usually a good idea to put a include guard on you header files to prevent conflicts if they are included multiple times. Alternatively you can use #pragma once, although its not part of the standard.

#ifndef HEAP_H
#define HEAP_H
 
class Heap 
{
public:
};
 
#endif
template<> 37 Junior Poster

Basic algorithm is to find a space and then remove all subsequent spaces.

Check out some of the std::string methods (find, erase)

http://www.cplusplus.com/reference/string/string/

template<> 37 Junior Poster

Depends on what you want/like to do and which platforms you are interested in...

Having said that, c++ is a good language to have in your skill set.

template<> 37 Junior Poster

Quote: "However, I am developing a collection of classes and I need them all to share a common variable (a time step) whose value will be defined by the user."

Since the values is defined by user, its similar to a configuration value, therefore const is probably not what you want.

A singleton that the user can initialize at startup maybe another alternative

template<> 37 Junior Poster

The code does not make any sense. Would be helpful to describe what you are trying to do in words. For example what are you trying to do with the while loop? What is the problem you're trying to solve?

template<> 37 Junior Poster
template<> 37 Junior Poster

A structure is a class where members are public by default, besides that technically speaking there are same. However by convention, structures are used to represent simple data structures and classes for more expressive functionality.

For this simple application, it’s not a big deal, but meticulous attention to Constructors and Destructors, including the initialization and order of initialization will save you hours of debugging time in the future.

template<> 37 Junior Poster

Are you trying to create an array of commands for the Robot to execute?

template<> 37 Junior Poster

What is your intent with these two lines?

char *pipebuf=new char[40001];
CommandRobot *cr= (CommandRobot*)pipebuf;
template<> 37 Junior Poster

Some questions to ask yourself.
1. class or structure?
2. Inside the class, you do not need this-> to reference data members
3. Initialize in constructor rather than assign

For example

struct Node
{
    int data;
    Node *preNode;
    Node *postNode;
    Node *parentNode;
    bool isEmpty;

    Node()
    : data(0)
    , preNode(NULL)
    , postNode(NULL)
    , parentNode(NULL)
    , isEmpty(true)
    {
    } 
};
template<> 37 Junior Poster

if isNull means all nodes are null, then an alternative is to have method to check nodes are null

template<> 37 Junior Poster

The pointers to nodes initialized to NULL make sense.

But what/how is the isNull used for?

template<> 37 Junior Poster

Why are we casting the pipebuf into a class??

template<> 37 Junior Poster

Let see some code for what your trying to do

template<> 37 Junior Poster

In c/c++ its a good idea to initialize variables to some known state. Unintialized variables causing problem has kept many a programmer debugging for hours.

In C++ Null is defined as 0. See section on "Should I use NULL or 0?" for some words of wisdom from the master himself.

http://www2.research.att.com/~bs/bs_faq2.html

iamcreasy commented: Awesome Link :D +2
template<> 37 Junior Poster

code is simple should work either way

template<> 37 Junior Poster

use the CODE blocks to demark your code, so its simpler to read

class Hello
{

};
template<> 37 Junior Poster

g++ -Wall main.cpp myclass.cpp friendclass.cpp -o friend

#ifndef MYCLASS_H
#define MYCLASS_H

#include "friendclass.h"

class MyClass
{
    public:
        MyClass();
        int GetprivVar1() { return privVar1; }
        //friend class FriendClass;
        friend void FriendClass::changeMyVariable(MyClass*);
    protected:
    private:
        int privVar1;
};

#endif // MYCLASS_H
/****************** FriendClass.h ***************/

#ifndef FRIENDCLASS_H
#define FRIENDCLASS_H

class MyClass;

class FriendClass
{
    public:
        FriendClass();
        void changeMyVariable (MyClass *);
    protected:
    private:
};

#endif // FRIENDCLASS_H
/****************** MyClass.cpp ***************/

#include "myclass.h"

MyClass::MyClass()
{
    privVar1 = 0;
}
#include "friendclass.h"
#include "myclass.h"

FriendClass::FriendClass()
{
    //ctor
}

void FriendClass::changeMyVariable(MyClass* obj)
{
    obj->privVar1 = 9;
}
#include <iostream>
#include "friendclass.h"
#include "myclass.h"

using namespace std;
int main()
{
    MyClass obj1;
    FriendClass obj2;
    cout<<"before : "<<obj1.GetprivVar1();
    obj2.changeMyVariable(&obj1);
    cout<<"after : "<<obj1.GetprivVar1();

    return 0;
}
template<> 37 Junior Poster

Make sure the cpp include the header files of what is needed

template<> 37 Junior Poster

I am able to compile and link using g++, with changes below.

1. in FriendClass.h remove MyClass.h include and provide forward declaration for MyClass

2. In MyClass.h include FriendClass.h

template<> 37 Junior Poster

Objects and thread work together well. Try to model your problem in terms of classes.

For example Shuttle can be designed as an active class

template<> 37 Junior Poster

What does you data look like?

template<> 37 Junior Poster

Iterate through the vector and use string find/replace

template<> 37 Junior Poster

Ok so start the debugger and step through the code. If you never used it before get someone to walk you through it...

template<> 37 Junior Poster

Rather than put raw pointers, a common technique is to use shared pointers, which use reference counting. Otherwise need to need to iterate and delete your own objects

template<> 37 Junior Poster

Get a few books on socket programming and start playing around. Two well know authors are W. Richard Stevens and Douglas E. Comer.

template<> 37 Junior Poster

Are you expecting the above code to compile?

template<> 37 Junior Poster

probably good idea to check return codes for errors. For example if you are not able to open the file...

template<> 37 Junior Poster

You could create one thread as a service thread that calls the public methods of your objects every minute...

template<> 37 Junior Poster

If you are on windows, it probably in your trash, which you can restore.

template<> 37 Junior Poster
template<> 37 Junior Poster

use a hex editor to change it and save exe.

template<> 37 Junior Poster

from within the q1_sort function, when it calls itself,

it needs to pass the typename like q1_sort<Tdata>(A, left, i-1);

(your original code has person type hardcoded in the function)

that should fix your undefined reference

template<> 37 Junior Poster

try this first quote...

"I'm assuming your using Visual Studio.
The easiest solution to this problem is to change your solution settings from Unicode to Multi-btye.
VS sets windows applications to default to unicode. While unicode "may" be better, it certainly is more difficult for beginning programming and requires explicit conversions.

Right click on your Project, select Properties. Configuration Properties/General
And Character Set to Multi-Byte."