kux 55 Junior Poster

ok, I tried to do some reasearch first, but haven't really found what I was looking for.

Each windows app uses a message queue that stores user input and calls the required event handler ( a simple way of putting it ... ). What I was thinking is that has to be a message queue at the kernel level, and the kernel dipatches each message to the process it belongs to ( correct me if wrong ). Now, if my assumption is true, I wonder if is there any system call to check upon this message queue and be able to view from one process what messages are dispached to other processes.

thx

kux 55 Junior Poster

If you are using MFC you can try something like:

CFile inFile("test.txt", CFile::modeRead);
CArchive archive(&inFile, CArchive::load, inFile.GetLength());
CString line;
while (archive.ReadString(line))
{
        // do something with <line> here
}
archive.Close();
inFile.Close();

hmmm,not shure, this kind of looks like you would load the entire file in memory. 4 very large file it would be very memory consuming i think

kux 55 Junior Poster
int howmuchIread = 0;
	while ( ( howmuchIread = fread ( buffer, 1, READSIZE, fp ) )  != 0 )
	{
		buffer[ howmuchIread ] = 0; //place terminal character to avoid overruns

I hope you realize that the code in the last line above will likely cause buffer overflow. Lets say howmuchIread == READSIZE, which is the same as sizeof(buffer). Then buffer[howmuchIread] will be one byte beyond the end of the buffer.

if u look closer at the code, u will see that buffer is buffer[BUFFSIZE], and BUFFSIE = READSIZE + 1, so... no overrun there :)

Ancient Dragon commented: Yes I missed that :) +36
kux 55 Junior Poster
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <string>
#include <vector>

using namespace std;


void tokenizestring( const std::string& src, const std::string& delim, vector<string>&tokens )
{
	string::size_type start = 0;
	string::size_type end;
        
        tokens.clear();
	for ( ; ; )
	{

		end = src.find ( delim, start );
		if ( end == string::npos )
			break;
		tokens.push_back ( src.substr ( start, end - start ) );

		start = end + delim.size();
	}

}

int main ( int argc, char* argv[] )
{

	FILE *fp;
	if ( (fp = fopen("c:\\test.txt", "rb")) == NULL )
	{
		printf( "unable to open file " );
		exit( 2 );
	}

	const int READSIZE = 1024;
	const int BUFFSIZE = READSIZE + 1;

	char buffer[BUFFSIZE]; // + 1 to have place for appending
				           //a terminal character

	vector<string> tokenized_byline;

	int howmuchIread = 0;
	while ( ( howmuchIread = fread ( buffer, 1, READSIZE, fp ) )  != 0 )
	{
		buffer[ howmuchIread ] = 0; //place terminal character to avoid overruns
		string sBuffer = buffer;


		//the trick is I call a fgets to get the rest of the line and append
		//it to the rest of sBuffer
		//if the file position indicator is at a newline beginning, no problem,
		//we just read another line
		if ( !feof(fp))
		{
			fgets(buffer, READSIZE, fp);
			sBuffer += buffer ;
		}

		//tokenizestring tokenizes using /r/n  as delimiter, and stores the tokenized
		//strings to the vector tokenized_byline
		tokenizestring( sBuffer, "\r\n", tokenized_byline);
               
                //now u process the strings in tokenized_byline however u want

	}


	fclose( fp );


}

ok, …

kux 55 Junior Poster

This is a new way for me to read a file so I have to first understand the basic steps.
I will assume a few things here to see If I understand the basics of this reading.

What happens first is that 1024 bytes is red into the buffer like a string. My question here. Is this the string: text ?
If it is, the first step here is to tokenise this large string. I know that each line in the file contain 8 different values since 7 Commas delimits them. Since there is 1024 bytes there must be a lot of lines here, so I don´t understand how this will be tokenised.
It must be a technique I dont know about.
I think I just start out like this.

while( fread(mybigbuff, 1024, 1, fp) )
{
      char* p = strtok(text,",");

well, as salem's post said, u don't tokenize what u read.. the strtok should be
char* p = strtok(mybigbuff,",");
because mybigbuff is where u read from the file

now what I sugest u to do:

first decompose the problem: my ideea would be 4 u to first tokenize the buffer line by line, and then use one line however u want....thus simulating the fgets function

kux 55 Junior Poster

Whilst 80 to 8 seems like a good win with minimal effort, I'm not sure that 8 seconds down to 1 or 2 is of any further benefit, given the sudden jump in code complexity (time to write, time to debug, time to maintain).

If it takes you 8 hours to do that, that's 28800 seconds.
At a saving of say 6 seconds a run, that's 4800 runs before you break even.

ohhh , come on, it can't take u EIGHT hours... :)

kux 55 Junior Poster

>> that means after one fread u get A LOT of lines in your buffer

Now I understand what 1 stands for and 8 is ofcourse wrong there. Also how it proccesses 1024 bytes each time and that it often will read into the middle of the lines.
If I leave this for a moment because now you got me interested in what "Memory mapped Files" is and how that work.
Could this be as fast as the fread() method ?

haven't tried it yet :P The idea is that u map a file in memory and no longer have tu use file I/O operations on it. It is suppose to be very fast for small files due to the fact u don't have to do system calls to read from the file, but for large files it can be slower than the fread version because of numerous page faults that can occur.

kux 55 Junior Poster

yeap, salem is right, but if u need speed....
another way would be to use memory mapped files

kux 55 Junior Poster

if u want to understand fread and setvbuff the best option is to check out their man pages. U can do so typing man fread in google or typing man fread on a linux terminal and having the C standard library documentation installed. Anyway, make it short, u can forget setvbuff as it won't help u much, as for fread:

size_t
fread(void *restrict ptr, size_t size, size_t nitems,
FILE *restrict stream);

ptr is the buffer to that to store the read information, size is the number of octets to read, and nitems is the number of size chunks to read => u actually read size * nitems bytes. What u did above is wrong: u actually read 8 * 1024 bytes in a shot. U should just stick to fread ( buffer, 1024, 1, fp ).

Ok, now considering u're file is ascii encoded, it means that each charater is one byte wide. U read exactly 1024 bytes, so that means after one fread u get A LOT of lines in your buffer. The downside of this approach is that it's up to u to correctly interpret the content of that buffer by looping succesive strtok calls to get data in your desired format. Another downside is that the file position indicator after one read can point anywhere, most likely somewhere inside a line, not it's end, so if u interpret the buffer content line by line, and the last line is not "complete", u …

kux 55 Junior Poster

I think I understand what u mean.
I remember the old days when I was doing a simple "snake" game in pascal.
Back then I was able to do something like

repeat
repeat
.......move snake in one direction.....
until keypressed();
..... process input key and change dirrection....
until forever

or something like it... The thing was that the snake was moving ( implemented in the loop ) and when an arrow key was pressed the direction would heve been changed. Ok, the only problem is that i don't know any standard C function that would do the samething thing as keypressed in pascal. The only alternative I can think about is having another thread that listens to user input, push the event in a global queue and have the "game running" thread process the event queue with user input. This is a more general approach, but I'm still wondering if C has any function like keypressed() :) . So if anybody can enlighten me... :)

kux 55 Junior Poster

hi guys,

i have declared a char pointer. i am using this in itoa() function to convert integer data into hex data e.g

char * hexData= NULL;
             itoa(1484820,hexData,16);

this results in equalent of 1484820 in hex decimal and store it in hexData.

now when I want to some process in hexData(char pointer). when I pass it to my function for further process, the value of hexData(char pointer is changed now contains garbage) see the code below

main()
{
char * hexData=NULL;
itoa(148420,hexData,16);
printf("%s",hexData);---------------------//output is 243C4
writeinFile(hexData,fptr);
}

writeinFile(char* str, FILE *fptr)
{

printf("%s",hexData);---------------------//output is 2434C but some time a garbage value
char *hex = new char[30];
printf("%s",hexData);---------------------//output is always garbage value after any new   
                                                          //char *pointer declaration.

----
----
----
}

}

I am confused whats problem going on here.
can any tell me its solution?


Asif

well, hexData points to unallocated memory ...
use:
char hexData[BUFFSIZE];
or
char * hexData = (char*)malloc( BUFFSIZE* sizeof( char));

u get garbage because u use unallocated memory that can be overwritten at any time

kux 55 Junior Poster

ok, I was actually curious to see the effect of setvbuf over fgets

#include <stdio.h>
#include <iostream>
#include <assert.h>
using namespace std;

int main(int argc, char* argv[])
{
	const char* fname = "d:\\test162MB.txt";
	FILE *fp = fopen( fname, "rb" );

	int x = setvbuf(fp, (char *)NULL, _IOFBF, 512);

	assert( x == 0 &&fp != NULL );

	char mysmallbuf[20];
	while ( fgets( mysmallbuf, 20, fp ) )
	{
	}

/*
	char mybigbuff[1024];
	while ( fread( mybigbuff, 1024, 1, fp ) )
	{
	}
*/
	return 0;
}

running the following code with fgets the 162 mb file is read in 8 secs
running with fread it is read in 2 secs. So my conclussion is that no intermediate 512 bytes buffer is for reading large chunks of the file ( I thought that calling the first fgets would read 512 bytes and store them in a buffer, and the next xxx fgets would get from the intermediate buffer, not directly from the file, thus having the same speed as the fread version, but it seems not, setvbuf just has no effect over fgets, fgets is by default linebufferd )

kux 55 Junior Poster

The only addition to Ancient Dragon's C stream library method: add setvbuf call after fopen:

const size_t BSZ = 1024*32 // or more
...
FILE* fp = fopen("..\\TextFile1.txt", "r");
if (fp) 
{
    setvbuf(fp,0,_IOFBF,BSZ); // No need to free buffers explicitly
    ...

Default stream buffer size is too small for huge files. You will get much more faster file reading. As usually, in VC++ C streams and data conversions are faster than C++ ones.
It's possible to accelerate C++ streams with a proper streambuf declarations but it's the other story and VC++ slow getline absorbs the effect...

Hmmm, i don't think calling setvbuf has any effect on reading a file. If u loop fgets calls the file is simply read line by line and the read info is placed direclty in the buffer u provide as parameter ( i think).
As far as I know, setvbuf sets the output buffer when writing a file, and as far as I know all file output operations are by default blockbuffered with the buffer set with the optimum size...
U're speed problem is that u read the file line by line. 4 optimum speed eff u should fread chunks of 512 or 1024 bytes ( the optimum size would be u're hdd cluster or sector size, or whatever ) and do the info processing in memory

kux 55 Junior Poster

hello... I am trying to convert 2 digit numbers to words: example 11= eleven. I saw some other entries on this but they dont include case or switch

well, here it is, if my number spelling is not quite correct...srry
a switch is still used, but it's much smaller than urs

#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	const char *digits[] = {"","one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
	const char *teen[] ={"ten","eleven", "twelve", "thirteen", "fourteen", "fiveteen", "sixteen", 
		"seventeen", "eighteen", "nineteen" };
	const char *big[] = { "", "", "twen", "thir", "four", "fif", "six", "seven", "eight", "nine" };
	

	if ( argc != 2 )
	{
		cout<<"cmd line argument req: the number to convert..."<<endl;
		return 1;
	}
	unsigned char nr = atoi( argv[1] );

	unsigned char nr = 33;
	if ( nr < 1 || nr > 99 )
	{
		cout<<"numbers between 1 and 99 accepted"<<endl;
		return 2;
	}

	unsigned char sdigit = nr % 10;
	unsigned char fdigit = nr / 10;

	char result[32]="";

	switch (fdigit)
	{
	case 0: strcat( result, digits[ sdigit ] );  break;
	case 1: strcat( result, teen[ sdigit ] );  break;
	default:
		strcat( result, big[ fdigit]);
		strcat( result, "ty");
		strcat( result, digits[ sdigit] );
		break;
	}

	cout<<result;

	return 0;
}
kux 55 Junior Poster

It's not only the way of solving the compile-time warning problem, it's the way of solving right (run-time) calculations problem.
If we have unsigned long i and unsigned short x = 0xFFFFu and unsigned short y = 0xFFFFu then i < x * y computations are:
1. Do integral promotions for both multiplication operands (unsigned short to int)
2. Multiply int to int (int result 0xFFFE0001, integer overflow ignored in VC++)
3. Do int to long promotion of 0xFFFE0001 (do nothing in 32-bit VC++) then long to unsigned long conversion (the same 0xFFFE0001u but positive now; do nothing in 32-bit VC++).
4. Compare i with positive 0xFFFE0001.
Strictly speaking we have an unportable code: some C++ implementation may diagnose integer overflow in step #2! So explicit cast of x and y is the way to do this code portable.

ok, thx :) . It works in msvc 2005 too. I mean the conversion in step 2 is done here too. Anyway.. soved problem... thx

kux 55 Junior Poster

the only logical explanation I can think of is that the conversion is done at runtime... The result of x*y overflows int, so it's converted to unsigned int.

kux 55 Junior Poster

It's so simple to solve your problem (if you can't follow skatamatic's advice):

for ( unsigned long i = 0; i < (unsigned long)x * (unsigned long)y ; i++ )

yes, I understand this is the way of solving the warning, but I'm still curious why if the implicit conversion is done from unsigned short to int the overflow doesn't occur. I mean if x = y =65535, then 65535*65535 = 4294836225 witch should be -131071 represented in int (4 bytes on my machine)=> the for should not loop at all. BUT IT DOES :)

kux 55 Junior Poster

I think it's a very interesting question. From the C++ Standard (4.5, 1):

No doubts that VC++ int type can represent all the values of unsigned short. So x * y result was promoted to int (not to unsigned int). That's why this diagnostic message was generated (unsigned long < int and so on)...

Ok, but then, if I replace x with let's say... 65535 and y with 65535 the x*y would overflow int and the result would be a negative value... Now that's a problem. I tried it... the expected result was that the for would get iterated 0 times... but surprisingly... it worked, it iterated till 4294836225, wich is ofc unsigned int :| . So... i still don't get it

kux 55 Junior Poster

Compile this code with MSVC2005

unsigned short x = 20;
	unsigned short y = 20;

	for ( unsigned long i = 0; i < x * y ; i++ )
	{	
		cout<<i<<endl;
	}

and u get

warning C4018: '<' : signed/unsigned mismatch

why? i mean, it all runs fine, j is iterated till 400 and, as I know, the short unsigned should be converted in an unsigned long when doing the comparison, so no overflow cand be possible ... And, why is it stated signed/unsigned mismatch when all variables are unsigned and no overflow is possible?

thx in advance

kux 55 Junior Poster

http://www.parashift.com/c++-faq-lite/pointers-to-members.html

this is a good tutorial on doing workarrounds in passing member function pointers.
If the static member is not suited, the other "function wraper" that uses a global object is probablly better

kux 55 Junior Poster

It's a long shot, but maybe while optimizing compiler got rid of unneeded functions and code in library?

funny :), I just replyed to your thread :))
yea, that is possible

kux 55 Junior Poster

I'm aware of that, but that's not the issue here.
If i go with string, when trying to access deleted memory site, OS gives an error (because of pointer accessing something he shouldn't)
If i go with my object, when trying to access deleted memory site, I can access it!

Yes, as grumpier said, when u try to dereferenciate freed memory, if your program crashes or not ... it depends on the type you try to dereferenciate... If you replace string with int in your previsorious example, the program is likely to not crash anymore... it will just read at the supplied mem adress and print what it finds there as an int . After you call delete, the freed memory adress might be set to some default values depending on your compiler, debug/release build, optimization level... or it might be left containging the same values as before so reading that memory adress again and expecting the same type might SEEM that nothing wrong happend. The fact that you deleted that piece of memory means that THAT block can be used for another allocation so might be overwritten at any time. So, everyting is "unexpected" when doing this...

kux 55 Junior Poster

I came accross a strange thing, maybe it's stupid, or I don't have the knowledge of how linking actually works...
I have a project that builds in a static lib, and anoter project that builds in an exe and links to the static lib. Compiled with MSVC 2005, all works well, but what is strage is that the exe has 3 Mb and the lib has 11Mb. How is this possible? I mean, if i link the exe to the static lib, shouldn't all of the obj code be included in the exe?

thx in advance

kux 55 Junior Poster

This may sound silly.

I have a class that contains a vector of pointers to instantiated objects.
I want to return a refrence to that vector, but I don't want to be able to modify the vector through that refrence.
Now, if i return a const reference, the vector is const, but the objects pointed by within the vector can still be modified via the pointer.

As a short example:

lass VecC
{
	vector<int*> myV;
public:
	VecC( int xx)
	{
		int *wtf = new int(xx);
		myV.push_back(wtf);
		
	};

	const vector<int*> & getV() { return myV; };
};

int main( int argc, char* argv[] )
{
	VecC obj(5);

	const vector<int*> & ref = obj.getV();

	*ref.at(0) = 9; // I WANT THIS TO NOT BE ALLOWED
}

Is this possible?
Thx in advance

kux 55 Junior Poster

yea, and when writting the assignment operator=, don't forget the assignemt to self problem

kux 55 Junior Poster

Are there any standard C++ libraries that support multithreading other than windows.h?

Well, there is no STANDARD C++ library that supports multithreading. windows.h is WinAPI, so it's not standard. If you want multithreading on win, you could use WinAPI, if you want multithreading on UNIX based you could use pthread. The best workarround and portable way would be to use boost multithreading library, it is portable ( it's actually a wrapper over all the operating system threading apis ). I hear the next C++ standard library realease will support concurency, but until then... :)

kux 55 Junior Poster

Hi

iam a newbie to C++
I have a problem, pls give me a solution

I have an object in the shared memory which encapsulates an array of 6 objects. I want to acess one of the objects in the array. If the first object in the array is already locked by a process, i want to get the second object and so on.

Please tell me how to do this and please let me know, how to check whether an object in the array is already locked by some process or it is free to access?

Thanks in Advance

Vadan

well, you could have another array of 6 bools that marks that the corresponding object in the info array is locked or not ( a flags array, or something ), only be very carefull about syncronization... the locking of an object from the array and setting the corresponding flag are 2 different operations... u must make them atomic!! if not, if a context switch is made between them and another process might then check the flags, it will find an object unlocked while it is actually locked but the flag is not properly set because of the context switch that happend between the locking of the object and the flag setting.

kux 55 Junior Poster

sorry dude, but this is just retarded. U want your test solved... ok, but firt get a fizics or mechanics book, get the formulas you require to calculate what you need and that's it. You just have to call a few function and add a couple of numbers. This is about programming not mechanics :|

kux 55 Junior Poster

From C++ Standard:

and another quote:

May be, it helps.

yes, it does :P, thx.

kux 55 Junior Poster

This is cited from Stroustrup third edition

void f () throw (x2 , x3 )
{
  // stuff
}
is equivalent to:
void f ()
try
{
  // stuff
}

catch (x2) {throw; } / / rethrow
catch (x3) {throw; } / / rethrow
catch (...) {
std: :unexpected() ; / / unexpected() will not return
}

Now take a look at the following code:

#include <iostream>
#include <string>

using namespace std;

class MyFEx
{
	string exMsg_;
public:
	MyFEx( string exMsg ): exMsg_(exMsg) {}
	void print() { cout<<endl<<exMsg_<<endl; } 	
};

class MySEx
{
	string exMsg_;
public:
	MySEx( string exMsg ): exMsg_(exMsg) {}
	void print() { cout<<endl<<exMsg_<<endl;  }	
};

void A(int x) throw ( MyFEx , MySEx )
{
	x < 0 ? throw MyFEx( "myfirst " ) : throw MySEx( "mysecond" ); 
}

void B(int x) throw ( MySEx )
{
	A(x);
}

void MyUnexpectedHandler()
{
	cout<<"OK, HANDLER CALLED"<<endl;
}


int main( int argc, char* argv[] )
{
	unexpected_handler theOldOne = set_unexpected( MyUnexpectedHandler );
	
	
	try 
	{
		B(-1);
	}
	catch(MyFEx& ex)
	{
		ex.print();
	}
	catch( MySEx& ex)
	{
		ex.print();
	}
	
	cout<<"ok, got here"<<endl;

	int i;
	cin>>i;
}

Ok, as I noticed the MSVC compiler, doesn't respect the standard, so don't bother compiling with it. It will compile but the result is that MyFEx will be cought in main althow B doesn't specify that it might throw a MyFEx, and the std::unexpected() handler is not even called.

If compiled with gcc the result is almost what I excpected:

kux 55 Junior Poster

I am deleting a pointer using "delete" in C++.
That pointer is holding the address which is used by OS like 0x00000210.
What will happens?

You got the problem all wrong. First you can't delete something used by the OS.
Your process has it's own adress space, so adress 0x00000210 is not the fizical memory adress, is just a virutal adress used by your own process, so you can't reference memory locations outside your own adress space.

Most likely if u do something like

int x = 0x00000210;
	void *p = (void*)x;
	
	delete p;

you will end up with an access violation and your program will terminate

kux 55 Junior Poster

Hi, I would like to ask you for help in converting this code from C to C++. It's my little friend 's homework, but I can't help him 'cause I know nothing about C :( In fact, I just can't figure the "scanf" part out, I think the other part is similar to C++. Thanks in advance !
[
#include <stdio.h>
#include <string.h>
void main()
{
int i,br=0,d=0;
char r[200];
printf("Vnesete Recenica\n");
gets(r);
d=strlen(r);
for(i=0;i<=d;i++)
{
if((r=='n')&&(r[i+1]=='o'))
{
r=' ';
r[i+1]=' ';
br++;
}
}
printf("Vo Vasata recenica se pronajdeni i izbrisani %d no zborovi\n",br);
scanf("%d",&i);
}

]

#include <iostream>
#include <string>

void main()
{
	int i,br=0,d=0;
	//char r[200];
	std::string r;
	//printf("Vnesete Recenica\n");
	std::cout<<"Vnesete Recenica\n"<<std::endl;
	//gets(r);
	std::cin>>r;
	//d=strlen(r);
	//for(i=0;i<=r.length();i++)
	/*
	for(i=0;i<r.length() - 1 ;i++) //THIS WAS INCORRECT IN THE 1st IMPLEMENTATION  TOO, BUFFER OVERRUN !!
	{
		if((r.at(i)=='n')&&(r.at(i+1)=='o'))
		{
			r[i]=' ';
			r[i+1]=' ';
			br++;
		}
	}
	*/
	std::string::size_type poz = -1;
	while ( true )
		if (  ( poz = r.find( "no", poz + 1 ) ) != std::string::npos )
			br++;
		else 
			break;
	

	//printf("Vo Vasata recenica se pronajdeni i izbrisani %d no zborovi\n",br);
	std::cout<<"Vo Vasata recenica se pronajdeni i izbrisani "<<br<<" no zborovi\n"<<std::endl;
	//scanf("%d",&i);
	std::cin>>i;
}

the last scanf/cin is placed there so that the program won't end untill the user sees the output and presses some key.
I placed the old C implementation between coments. It …

kux 55 Junior Poster

I've been searching for a memory leak detection tool for windows, something similar to valgrind under Linux, but all tools that i find cost, or just have free trials. Does anyone know a FREE memory leak detection tool for windows ?

kux 55 Junior Poster

first model:

class MyException
{
	string message;
public:
	MyException( string msg ): message( msg ) {};
	void printmsg() { cout<< message <<endl<<endl; }
};

void willthrow()
{
	throw MyException("mk");
}


int main(int argc, char * argv[])
{
	try
	{
		willthrow();
	}
	catch( MyException &ex)
	{
		ex.printmsg();
	}
}

second model:

class MyException
{
	string message;
public:
	MyException( string msg ): message( msg ) {};
	void printmsg() { cout<< message <<endl<<endl; }
};

void willthrow()
{
	throw new MyException("mk");
}


int main(int argc, char * argv[])
{
	try
	{
		willthrow();
	}
	catch( MyException *ex)
	{
		ex.printmsg();
                delete ex;
	}
}

it is clearly that in the second implementation the MyException object is allocated on heap, but how about the first one? What's the mecanism behind it? It would look like it's placed on the stack and then cought by reference, but how can it be placed on the stack if that is what exceptions do, unwind the stack till an apropriate catch clause is found. I mean, the stack pointer drops and when u catch the exception the reference points to an exception object above the current stack pointer... I don't know maybe i'm wrong. Can someone please explain how things actually work?

kux 55 Junior Poster

thx a lot dude, the typename Btree<T>::Element* was the answer :), the Element *p = new Element( T ) was not what I meant to write, but I overlooked it when sent the mail. cheers

kux 55 Junior Poster

I try to create a generic binary tree class but when i try to define an inserting function I get these compilation errors

error C2072: 'Btree<T>::recins' : initialization of a function
error C2143: syntax error : missing ';' before '*'
error C2275: 'Btree<T>::Element' : illegal use of this type as an expression
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
fatal error C1903: unable to recover from previous error(s); stopping compilation

this is the code:

template <class T>
class Btree
{
private:
	
	struct Element
	{
		T data_;
		Element* left_;
		Element* right_;
		Element( T &obj, Element* left = NULL, Element* right = NULL ):data_(obj), left_(left), 
			right_(right) {};
	};
	Element* root_;

	Element* recins( T& obj, Element* cpoz );
	void recprint( Element* cpoz );

public:
	Btree( T& obj );
	Btree( const Btree& btree );
	Btree& operator=(const Btree &btree);

	void insert( T& obj  );
	void printAll();

};


template <class T>
Btree<T>::Btree( T& obj)
{
	root_ = new Element( obj );
};


template <class T>
void Btree<T>::insert( T& obj )
{
	if( root_->data_ < obj )
		root_->left_ = recins( obj, root_->left_ );
	else 
		root_->right_ = recins( obj, root_->right_ );
};



template <class T>
Element* Btree<T>::recins( T& obj, Element* cpoz )
{
	if ( cpoz == NULL )
	{
		Element *p = new Element( T );
		return p;
	}
	else if ( cpoz->data_ < obj )
	{
		cpoz …
kux 55 Junior Poster

I try to create a generic binary tree class but when i try to define an inserting function I get these compilation errors

error C2072: 'Btree<T>::recins' : initialization of a function
error C2143: syntax error : missing ';' before '*' c:\documents and settings\kux\my documents\visual studio 2005\projects\btrees\btrees\btree.h 54
Error 6 error C2275: 'Btree<T>::Element' : illegal use of this type as an expression c:\documents and settings\kux\my documents\visual studio 2005\projects\btrees\btrees\btree.h 54
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\kux\my documents\visual studio 2005\projects\btrees\btrees\btree.h 54
Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\kux\my documents\visual studio 2005\projects\btrees\btrees\btree.h 54
Error 9 fatal error C1903: unable to recover from previous error(s); stopping compilation c:\documents and settings\kux\my documents\visual studio 2005\projects\btrees\btrees\btree.h 54

kux 55 Junior Poster

What i want to do is write some of the rows of a report style CListCtrl with a color and other rows with another color, but if I switch the color with SetTextColor the color of the text in the entire control switches, i want it to switch just for the rows I set till the next color switch

Is this possible? If you know it is, plz enlighten me :)

thx a lot

kux 55 Junior Poster

hello

Is there any way of getting the selected date in a CDateTimeCtrl in a CString or char* or anyting?

thx in advance

kux 55 Junior Poster

I understand that visual studio has a nmake tool for building a project from a makefile.
What I want to do is to be able to build my project outside the Visual Studio IDE, from command line using nmake.
I found some tutorials about writing a windows makefile for nmake, but I think visual studio should be able to do this automaticlly.
So, my question is, how do I generate this makefile from visual studio 2005? Of course, if that is possible

thx in advance

kux 55 Junior Poster

I have a project that builds in a static library, using visual studio 2005
When I build it in debug mode it all goes fine, but when I build it in release i get the following error:

Error 2 error C3861: '_SCL_SECURE_VALIData': identifier not found in file xtree

I disabled optimization in release mode so that it would be similar to debug mode but the problem is still there

the outputlog looks like

Exception.cpp
C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(297) : error C3861: '_SCL_SECURE_VALIData': identifier not found
C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(288) : while compiling class template member function 'bool std::_Tree<_Traits>::const_iterator::operator ==(const std::_Tree<_Traits>::const_iterator &) const'
with
[
_Traits=std::_Tmap_traits<unsigned int,std::string,std::less<unsigned int>,std::allocator<std::pair<const unsigned int,std::string>>,false>
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(413) : see reference to class template instantiation 'std::_Tree<_Traits>::const_iterator' being compiled
with
[
_Traits=std::_Tmap_traits<unsigned int,std::string,std::less<unsigned int>,std::allocator<std::pair<const unsigned int,std::string>>,false>
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\map(168) : see reference to class template instantiation 'std::_Tree<_Traits>::iterator' being compiled
with
[
_Traits=std::_Tmap_traits<unsigned int,std::string,std::less<unsigned int>,std::allocator<std::pair<const unsigned int,std::string>>,false>
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\map(167) : while compiling class template member function 'std::basic_string<_Elem,_Traits,_Ax> &std::map<_Kty,_Ty>::operator [](const unsigned int &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>,
_Kty=unsigned int,
_Ty=std::string
]
c:\documents and settings\kux\my documents\visual studio 2005\projects\projviki\defps\Exception.h(18) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
with
[
_Kty=unsigned int,
_Ty=std::string
]

and Exception.h:

#pragma once
#include …
kux 55 Junior Poster

Hello,

I have a CListCtrl and a button to modify the selected row in the CListCtrl.
My problem is that my list has several columns and I want to be able to select a row by clicking on any column of the row that I want selected. Now I can only select a row by clicking on the value found on it's first column. I think it's something about the CListCtrl propertyes , but can't figure out what has to be set.

Thx in advnace

kux 55 Junior Poster

what method is to be used to get the selected row in a CListCtrl ?
i tryed GetCount() but it returnes the number of selected items
i searched the method list, but found no GetRow() or something

thx in advance

kux 55 Junior Poster

I need some guidance in a little project.

I want to make a Document/View project that opens some planing files.
I want the view for this files to be something like an excel sheet so you can modify the values of some fields and then be able to call some functions that fill some more fields. What must i use for this? I tryed to use a CListView, but I don't actually know what has to be done as I am pretty new in MFC apps. Any help is welcomed.

thx in advance

kux 55 Junior Poster

I have a vector<classType> vect
in order to call sort( vect.begin(), vect.end() ), what needs implemented in the class classType?
I have the overloaded operator< and a copy constructor, but the problem i get is that some member variables of classType that are pointers dereferenciate during the call to the sort function.

thx in advance

kux 55 Junior Poster

I have a function that recives as one of the parameters a function pointer.
If i want to pass a class method as that function, how do I do it?

I tryed like this:

class C
{
public:
   SetVector( vector<UTF16> );
};

//function prototype
void function( const string sToPlace,  void(*setter)(vector<UTF16>) );

and i call it like this:

function( stringVariable, objC->SetVector ); //where objC is an instance of C class

but it doesn't seem to work. the functoin is supose to do some string manipulating on the stringVariable, extract a vector from int and call the setter

kux 55 Junior Poster

hello,

I have the following problem
I have an unsigned long variable, but it is designed to hold values within 0 .. 100 ( I know an unsigned char would have been enough, but i have to use an unsigned long ).
I have to write that value in a file on a single byte.

if i do fwrite(&unsignedlongvar, 1, 1, file ) it will write the octet on the lowest adress of the variable. If the system is little endian this is ok because that is where the value I am intrested in is, but if the system would be big endian the value I am intrested in would be at the highest adress and the fwrite would write the lowest octet. How do you suggest solving the porting problem? Is there any standard function to test the endianess of the system?

thx in advance

kux 55 Junior Poster

hmm, this is wierd....
try posting the whole code, or a bigger sample...

as for g++, u have to add flags in order to use precompiled headers, if no flags are added precompiled headers are not used... so normally u compile u're code without using them

kux 55 Junior Poster

I just started using Eclipse for developing C++ projects.
I wanna ask u guys if u know any good forums for posting regarding this IDE, or if some of u guys arround here use it also, so I know if it would make sense to post arround here or not.

thx in advance

kux 55 Junior Poster

plz take a look at the following code

#include <iostream>
#include <string>

#include <iostream>
#include <string>

using namespace std;

class A
{
public:
	string sa;
	A(string sia);
	
};

class B:public A
{
public:
	string sb;
	B(string sia, string sib);

};

A::A(string sia):sa(sia)
{
}

B::B( string sia, string sib):A(sia),sb(sib)
{
}

int main(int argc, char*argv[])
{
	string param1="abcd";
	string param2="efgh";
	A *b;
	b = new B(param1, param2);
	delete b;
	return 0;
}

the thing is when compiling with gcc and running with valgrind i have a memory leak
the valgrind output regarding the leak is:

==12855== 17 bytes in 1 blocks are definitely lost in loss record 1 of 1
==12855== at 0x40232B4: operator new(unsigned) (vg_replace_malloc.c:224)
==12855== by 0x40D5FF0: std::string::_Rep::_S_create(unsigned, unsigned, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.9)
==12855== by 0x40D7334: (within /usr/lib/libstdc++.so.6.0.9)
==12855== by 0x40D74E6: std::string::string(char const*, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.9)
==12855== by 0x8048B26: main (executable.cpp:11)

if someone could explain me the reason of the leak i would be very thankfull

thx