You have to initilialize the FOO in constructor, FOO is a reference and has to initialize in contructor

[CODE]
class baz
{
private:
int foo;

public:
const int & FOO;
baz() : FOO(foo) {} // constructor
~baz(){ } // destructor

};
[/CODE]

hmm, it compiles without problems with gcc.

How do you compile it?

Some things got messed up it should be like this:

main.cpp

[CODE]//file1.cpp

include
include"file3.h"

using std::cout;
using std::cin;

namespace baz
{
extern MyClass foobar;
}

int main()
{
baz::foobar.setFOO();

baz::foobar.bar();
cout << *baz::foobar.FOO << "\n";

cin.ignore();

return 0;

}
[/CODE]

[CODE]
//file3.h

namespace baz{

class MyClass
{
private:
int foo;

  public:      
  void bar(void);
  void setFOO(void);
  int * FOO;

};

}[/CODE]

[CODE]//file2.c

include"file3.h"

namespace baz
{
MyClass foobar;

void MyClass::bar(void)
{
     foo = 42;
}

void MyClass::setFOO(void)
{
     FOO = &foo;     
}

}

[/CODE]

Hi!

Can you be more specific?

i see, well when i will do it like this:

[CODE]void check_name()
{ name *strt;
strt = start_ptr;
cout << endl;

      for (name * strt = start_ptr;strt->nxt !=NULL;strt=strt->nxt)
      {      

        if (enter_name == strt->boy_name )
        {
            cout << enter_name << " is ranked #" << strt->rank;
            cout << " in popularity among boys.\n" << endl;
            break;
        }
        else if (enter_name == strt->girl_name) 
        {
             cout << enter_name << " is ranked #" << strt->rank;
            cout << " in popularity among boys.\n" << endl;
             break;

        }
      }
cout << enter_name << " is not ranked among the";
  cout << " top 1000 names." << endl;

}[/CODE]

call check_name() after add_names();

Full code:

[CODE]#include

include
include

using namespace std;

struct name
{ int rank;
string boy_name;
string girl_name;
name *nxt;
};

name start_ptr = NULL;
name
current;

void add_names();
void check_name();

string enter_name;

int main()
{
start_ptr = new name;
cout << "Please enter a first name to see its ranking" << endl;
cout << "among the top 1000 baby names." << endl;
cin >> enter_name;
cout << endl;
add_names();
check_name();

system("PAUSE");
return 0;

}

void add_names()
{ //name temp, temp2;
//temp = new name;
name prior = new name;// temp;
int ranking;
//int i=0;
string male_name, female_name;
ifstream in_stream("babynames2004.txt");

//in_stream.open; //opens and loads names & ranks from file
if (in_stream.fail())

{
cout << "File failed to open." << endl;
cout << "Program will now close." << endl;
system("PAUSE");
exit(0);
}

in_stream >> ranking>> male_name >> female_name;

prior = ...
mcap61 commented: Saved my a$$. Thanks for your help, I wish i could return the favor. +1

i would do it like this: [url]http://clipboard.it/v/z2b/[/url] no pointers, better to understand.

Hi!

Sorry the [url]http://www.cs.nccu.edu/~gmilledge/co...ynames2004.txt[/url] doesnt work.

I think you should use std::list, and no pointers if it's not neccessary! It will make your wile easier ;)

[CODE] strcpy(can->name, ch );[/CODE]

better use std::string.

gcc doesn't complain, hmm.

it's looks like Splint has a problem.

did you try:
[CODE]
int r = scanf("%f%f", &height, &weight);

float bmi = (float)weight/(height*height);
[/CODE]

he doesn't like:

[CODE]vector<int[3]> resolutions;[/CODE]

should be:

[CODE]vector resolutions;[/CODE]

if you need an array:

[CODE]vector<list> resolutions;[/CODE]

kirennian commented: Problem solved, thanks. +1

did you try:

[CODE]typedef struct DISPLAY_DEVICE_CAPABILITIES{
vector<int[3]> resolutions;
int brightness;
}DISPLAY_DEVICE_CAPABILITIES;[/CODE]

You should type cast it:

[CODE]float bmi =(float) (weight/(height*height)); [/CODE]

You welcome!

if you have it like this:

[CODE]void *ptr;[/CODE]

and give it to send, send will complain, because behind ptr is no memory allocated!

did you try:

[CODE]int i=0;
int ch=recv(new_socket,(void*)&i,sizeof(int),0);
printf("Value of a is :%d\n", i);[/CODE]

you need to type cast it:

[CODE]const int constPtr2=(const int)ptr2; [/CODE]

and to make it more smooth

instread of:

[CODE]strcat(strfinal, "HTTP/1.0 200 OK \r\n\r\n");
if (myfile.is_open()) //if the file is open
{
while (! myfile.eof() ) //while the end of file is NOT reached
{
getline (myfile,line);
cout << line << endl;
strcat(strfinal, line);
}
}
send(newsockfd, strfinal, sizeof(strfinal), 0);[/CODE]

better:
[CODE]

include

[/CODE]

[CODE]
std::sstream ss;

ss << "HTTP/1.0 200 OK \r\n\r\n";

if (myfile.is_open()) //if the file is open
{
    while (getline (myfile,line) ) //while the end of file is NOT reached
    {
        cout << line << endl;
        ss << line;
    }
}  

send(newsockfd, ss.str().s_str(), ss.str().size(), 0);[/CODE]

line 36:
should to be: std::string line;

line 80:
strcat(strfinal, line.c_str() );

instread of:

[CODE]while (! myfile.eof() ) //while the end of file is NOT reached
{
getline (myfile,line);
cout << line << endl;
strcat(strfinal, line);
}[/CODE]

better:

[CODE]while (getline (myfile,line)) //while the end of file is NOT reached
{
cout << line << endl;
strcat(strfinal, line);
}[/CODE]

Hi!

I would create a base class, from which the myTemplateClass will inherit.

like this:
[CODE]
class TemplateClassBase{};

templateclass myTemplateClass : TemplateClassBase{};[/CODE]
This should be a list:
[CODE]myTemplateClass templateClassPtrArray[10];[/CODE]
This is better:
[CODE]std::list<TemplateClassBase
> templateClassPtrArray;[/CODE]

[CODE]templateClassPtrArray.push_back( new myTemplateClass() );
templateClassPtrArray.push_back( new myTemplateClass() );
[/CODE]

Code is NOT tested, was written from scratch.

When you have no problem to save anything.

I hope i was clear :/

It's the same.

Well, maybe you should redesign your program? It looks odd.

did you try without "endl"?

one of your variabes, does not support the >> operator.

Which type are the variables:
lvl
xp
str
spd
acc
hp
inventory?

Your are in the right way.

Well, String is not string. You have to write it in lowercase.

[CODE]void toString();[/CODE]

should be:

[CODE]void toString(string &target);

void Employee::toString(string &target){
target = "Name: " + empName + " / Employee Number: " + empNum + " / Hire Date: " + hireDate;
}
[/CODE]

Works fine for me. Can you provide how and with what you tested it then it's freezes?

hmm maybe like this:

[CODE]#pragma warning(disable:4786) // disable debug warning

include // for cout etc.
include // for vector class
include // for string class
include // for sort algorithm
include // for random seed
include // for abs()
define GA_POPSIZE 2048 // ga population size
define GA_MAXITER 16384 // maximum iterations
define GA_ELITRATE 0.10f // elitism rate
define GA_MUTATIONRATE 0.25f // mutation rate
define GA_MUTATION RAND_MAX * GA_MUTATIONRATE

//#define GA_TARGET std::string("Hello world!")

using namespace std; // polluting global namespace, but hey...

struct ga_struct
{
string str; // the string
unsigned int fitness; // its fitness
};

typedef vector ga_vector;// for brevity

void init_population(std::string &target, ga_vector &population, // new parameter
ga_vector &buffer )
{
int tsize = target.size();

for (int i=0; i<GA_POPSIZE; i++) {
    ga_struct citizen;

    citizen.fitness = 0;
    citizen.str.erase();

    for (int j=0; j<tsize; j++)
        citizen.str += (rand() % 90) + 32;

    population.push_back(citizen);
}

buffer.resize(GA_POPSIZE);

}

void calc_fitness(std::string &target, ga_vector &population)//new parameter
{
//string target = target; // new parameter
int tsize = target.size();
unsigned int fitness;

for (int i=0; i<GA_POPSIZE; i++) {
    fitness = 0;
    for (int j=0; j<tsize; j++) {
        fitness += abs(int(population[i].str[j] - target[j]));
    }

    population[i].fitness = fitness;
}

}

bool fitness_sort(ga_struct x, ga_struct y)
{ return (x.fitness < y.fitness); }

inline void sort_by_fitness(ga_vector &population)
{ sort(population.begin(), population.end(), fitness_sort); }

void elitism(ga_vector &population,
ga_vector &buffer, int esize )
{
for (int i=0; i<esize; i++) {
buffer[i].str = population[i].str;
buffer[i].fitness = population[i].fitness;
}
}

void mutate(std::string &target, ga_struct &member)//new parameter
{
int ...

redrum237 commented: brilliant! thank you, just what i was looking for +2

Sorry i dont get the point?!

SSL lib have own functions, but it's still the same socket function in SSL Lib

[url]http://www.openssl.org/docs/[/url] is your friend

ausrasul commented: good answer +1

like this?

[CODE]#include

include
include

using namespace std;

//void calculateAverage();
//int calculateGrade();
//void updateFrequency();

int main()
{
//const int size=10;
//int debug=size;
string tmp;
//int test1[size], test2[size], test3[size], test4[size], test5[size];

ifstream infile;
/*
for(int i=0;i<size;i++)
{
    test1[i]=0;
    test2[i]=0;
    test3[i]=0;
    test4[i]=0;
    test5[i]=0;
}

*/
cout<<"Reading from file ''input.txt''..."<<endl;
infile.open("input.txt");

if( infile ){

    while( getline(infile, tmp ) ){
        cout << tmp << endl;
    }
}

/*
while(size==debug)
{
for(int i=0;i<size;i++)
{
infile>>test1[i];
infile>>test2[i];
infile>>test3[i];
infile>>test4[i];
infile>>test5[i];
}
debug--;
}

for(int i=0;i<size;i++)
{
    cout<<test1[i]<<" "<<test2[i]<<" "<<test3[i]<<" "<<test4[i]<<" "<<test5[i]<<" "<<endl;
}
*/

infile.close();
#ifdef __LINUX 
system("pause");
#endif
return 0;

}[/CODE]

not necessary: std::ifstream read("file.txt", std::ios_base::ate );
std::ios_base::ate = At The End

i tested it ;)