JasonHippy 739 Practically a Master Poster

>>initialize static member function
>>initializing a function

These two things doesn't mean anything in C++. You don't initialize a function. You initialize an object ( or a variable, whatever you call them).
Things you can do with functions are:
Declare them
Define them
Call them
Overload them
Templatize them
May be more but I just cannot think of them right now.

There is no thing as initializing a function (or member function)

To follow on from this reply if I may, and the original question:

Typically you'd usually use a public static member function as an external interface to your class...
In other words, they can be called from outside of the class and also without there necessarily being an active instance of the class!

For example if you had a singleton object, you'd usually include a public static member function in it's class definition to return a pointer to the one and only instance of the object (which could be stored in the class as a private static object, or as a static object in the class's namespace).

That way if other external classes/objects need to be able to access/use your singleton, they have a means to access it.

Offhand I can't think of any practical examples for protected/private static functions...But I'm sure some of the more experienced programmers on here can expand on this!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Ah, I see niek_e snuck in there with the answer while I was writing my last post!

JasonHippy 739 Practically a Master Poster

In windows, by including shlobj.h you can use a call to determine the path to the users desktop using the following:

// This variable will store the path to the users desktop
LPSTR desktopPath = new CHAR(MAX_PATH);

// this function call will populate the variable above with the path to 
// the users desktop....
SHGetSpecialFolderPath(0, desktopPath, CSIDL_DESKTOPDIRECTORY, 0);

I've not done any programming for unix/linux (yet!), so I don't know anything about the various API's/libraries involved, but I'm sure there will be some equivalent functionality somewhere in the *nix codebase to do this. If anybody knows what it is, then that will be the most likely solution to this thread!

Hope this is in some way useful.
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Hai everyone
I need a clarification on the following issue

Why does C++ compiler doesn't allow, to initialize static member function inside a class

And please do tell me about what is meant by initializing a function (member function)

Please help me in getting it clear
thank you

Have a nice day

I'm not sure I understand what you mean, can you post some example code to show us the problem you're having?

Jas.

JasonHippy 739 Practically a Master Poster

Hi, I have a question with ofstream, is there anyway to ask the user for a file name, then create the file, and write to it?
Like:

string file;
cout << "Enter filename:";
getline(cin, file);
ofstream ofile;
ofile.open(file);
ofile << (stuff....);
ofile.close;

...except that doesn't work properly.:S
Thanks for any help.

Assuming you're using a std::string to hold your filename, I think you just need to convert it to a c style string in your call to ofile.open....
i.e.

ofile.open(file.c_str());

Hope this is of some help,
Jas.

JasonHippy 739 Practically a Master Poster

The easiest way would be to use the ios::app flag, this will open the file in append mode if the file exists, if it can't find the file, a new one will be created.

ofstream myfile;
myfile.open("path\filename.ext", ios::app );

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I wouldn't say it's impossible to do, but it depends on how complex you want to make the app.

Using Flashdevelop and AS3, I recently made a simple flash app to put onto my active desktop at work so I can leave TODO notes on my desktop, or aimlessly doodle while waiting for long debug builds to finish...I've set up the flash file to be the same colour as a real post-it note, and set it up so that certain keys change the pen colour and size, clear the drawing area or restore the original pen colour/size settings. The whole thing uses the standard drawing API and took less than 30 minutes to throw together.

To do it was just a case of creating a main class for the flash file, initialising the drawing area and setting-up the initial pen size and colour using a call to graphics.linestyle.

Then set up some listeners and handlers for keyboard events(KEY_DOWN) and mouse events (MOUSE_DOWN and MOUSE_UP).

In the MOUSE_DOWN event handler, make a call to graphics.moveto to move the graphics cursor to the mouse cursor position and set up a listener for the MOUSE_MOVE event and a handler to do the drawing. Then in the MOUSE_UP remove the MOUSE_MOVE listener..

In your handlers for keyboard events, you check the keypresses and call whatever functionality you've created for that key (i.e. change pen size, or pen colour using graphics.linestyle)...

Once you've got that working, you can gradually …

JasonHippy 739 Practically a Master Poster

I think the only way of doing it would be to create an event dispatcher in your Activity class and then set up a listener in your main class to listen for messages from the dispatcher in Activity. Then use an event handler to pass text into your Status class.

Jas.

JasonHippy 739 Practically a Master Poster

Oops, seems like I am asking too much question in this forum.... hehe..

So now in the first frame, I put (using the GUI tools) a textfield in flash CS4 and give it an instance name "Status". What I want to do is to update this status from other classes like:

public class Activity extends Sprite {
  public function DoIt() {
     /* do something */
     if(stage!=null) stage.Status.text = "done";
}
}

my problem is that "Status" cannot be accessed. Question: are objects created by the GUI automatically "private"? or what have I done wrong?

Now in the first frame of the fla i add some AS3

var activity:Acitvity = new Activity();
stage.addChild(activity); // makes activity.stage != null
trace(Status.root) // mainTimeLine, so the mainTimeLine is not in DisplayList, not under stage
trace(Status.parent) // mainTimeLine
stage.addChild(Status)// place it on stage, hope activity can access it
trace(Status.root) // stage
trace(Status.parent) // stage

Question: activity still cannot access stage. so what is the difference between mainTimeLine and stage?

I could be wrong, but I believe that the stage is only accessible from the main class in your app. I've not used CS4 before, but I have found this problem when coding AS3 projects in Flashdevelop.

Consider this pointless random example, this is a Flashdevelop example!

We have a simple class called Thing which just contains a single property called thingSize, which we are trying to set to the value of stage.stageHeight/4:

package 
{
	
	/**
	 * ...
	 * @author Jason Trunks
	 */
	public class …
JasonHippy 739 Practically a Master Poster

Does Anyone know how to convert ordinary images to vector images in photoshop? How do you do it in the simplest way?

I just realized something. Publishers want vector graphics versions of drawings so they can enlarge or reduce the size of the drawing without problems related to changes in resolution.

But if a vector graphics image that is a raster scan of a photograph is enlarged or reduced, the scan lines will be overlapped or separated, and the photo would no longer appear to be a photo. This defeats the purpose.

Hence taking a picture with say a 10MP or greater camera and using that for pictures in advertisements. It should be more than large enough and shrinking is not too much of a problem.

Of course, you guys are assuming that the original poster wanted to convert photo's or complicated raster images to vector graphics.

But the poster could equally just have some simple graphics, perhaps originally saved as a .jpg or .png and want to convert them to vectors....In which case the bitmap tracing tools should yield good enough results!

In my last job we had a client who had several flash based e-learning programs originally created by a third party, which they wanted updated and optimised.

The flash files were all AS2 for flash player 7 a nightmare of timeline animation and layers UGH! {shudders}. So we ended up redoing the projects in Actionscript3 for flash player 9...much nicer!

One of the …

JasonHippy 739 Practically a Master Poster

I see that this has already been solved, but regarding a couple of points....

So I suddenly realise alot of people are talking about and using Flashdevelop to create swfs. So is this thing better than the original Adobe Flash?

I wouldn't necessarily say better, but an equivalent alternative; as the workflow is slightly different!

I've been using FlashDevelop since version 2 and it's a great way of creating flash content quickly in code. The main advantage (from a programmers point of view) being that there is no need for any of that messy timeline stuff. You just create classes for everything in your flash file and script everything. No more .fla's with hundreds of layers with code on various frames of the timeline, or code buried deep inside nested movie-clips!

Your source ends up being a lot clearer. Of course, you can create flash files just as easily in code using the Flash IDE without having to use the timeline or loads and loads of layers, but Flashdevelop is free and does the job well, whereas Flex Builder and Flash CS3/CS4 cost money (Although, flex builder is considerably cheaper than CS4!).

So if you're more of a coder or on a budget, then Flashdevelop or Flex-builder are definitely the way forward. If you prefer to stick to the more traditional flash/timeline style of programming and you can afford it, then CS3/CS4 are probably best.

Of course a major advantage of owning CS4 Pro would …

jakesee commented: Good effort in explaining. Thanks a lot. +1
JasonHippy 739 Practically a Master Poster

Hi all,

The previous flash 8 I used has got an swf player such that when I open the swf from the windows folders, the swf runs in its own standalone player. (not the exe projector)

But recently I tried to do the same for Flash CS4, the swf does not run. During the installation I skipped all the other misc programs. Is anyone of them required to run the swf?


Regards
Jake

I'm not sure I follow you? I got that you had flash 8 installed and clicking the .swf runs it in a standalone player, but what's happening with CS4?? What extra programs did you skip?? I've not used CS4, so I don't know what ships with it! For all of my AS3 stuff I've been using Flashdevelop, but I still use flash 8 pro for video encoding!

It sounds like you don't have flashplayer installed properly...
If no .swfs work at all, then you need to install the latest version of flash player.
If your old flash 8 .swf's work but the .swf's created in CS4 don't, then you'll need to update your flash-player to the latest version.

Other than that, I can't really see a problem!

JasonHippy 739 Practically a Master Poster

Hi all,

Need some advice here: I wrote some code to recieve KeyboardEvents but when I "Test Movie" inside the flash program, many keys are being captured by the flash program instead of my swf test movie. Most notably, all alphabets are trapped only numbers are detected within the swf. if I embed in html and run it in a web brower, it works fine.

is this the correct behavior? Isn't this ... quite dumb? Is there anyway to fix this?

Thanks!

PS: BTW, I'm utterly surprised there's no dedicated forum for flash here. Why?

So your actionscript is ok, and it picks up keypresses properly in an external instance of flash-player or on a web page but not when debugging in the IDE?

Sounds like the keybindings for your IDE are intercepting your keypresses, so they are not even getting to your .swf. There isn't really a lot you can do about it.

If you're using Flashdevelop to build and test your .swfs, you can set your options to allow you to test movies in an external instance of flash-player instead of an instance embedded in the IDE. That should solve the problem.

But if you're using one of the Adobe Flash IDE's, I'm not sure if you have the option to do this or not...Might be worth taking a look. If not, I'd recommend opening your .swfs directory and manually running the .swf to test it...which sucks, but it's the only way!

You'll also …

JasonHippy 739 Practically a Master Poster

Does Anyone know how to convert ordinary images to vector images in photoshop? How do you do it in the simplest way?

You can use illustrator by importing the image and use the "live trace" and this is the easy way..u can draw it also using pen tool.
another way is using flash, after importing the image select Modify> bitmap> trace bitmap. but you have to adjust some options.
Hope it works for you :)

The above post is a helpful solution to your problem, but on the offchance that you don't have access to any of the programs mentioned above (or can't afford to buy them), then Inkscape is a free alternative for creating vector graphics and also features a bitmap tracing tool (i.e. bitmap/raster to vector conversion!)

JasonHippy 739 Practically a Master Poster

Hello everyone,

I am in the process of developing a crossword puzzle website at

I want to start adding Flash crossword puzzles to the site. However, I am no Flash developer. Is there any software available that would allow me to easily create Flash Crossword Puzzles for my site without having to use the Adobe Flash program.

Thanks

If you are asking whether there are any programs out there that will allow you to create a crossword puzzle and export it as a flash file...Then I'm afraid I can't help you... I don't know of any software that does this..

But if you want to have a go at creating the flash content yourself without having to spend shedloads of cash purchasing Adobe Flash, then you could try downloading FlashDevelop from flashdevelop.org (http://www.flashdevelop.org) and the Flex3 SDK (a free download from the Adobe website).

FlashDevelop is a free, open source IDE for the windows .NET platform which allows you to create Flash content for free...All you do is download and install the latest version from flashdevelop.org, then download the Flex3 SDK from adobe. Set Flashdevelop up to point to the Flex3 SDK and away you go! You can then develop your flash content in code using Actionscript 3.

Flashdevelop is only available for windows/PC at the moment (I think!), but there is also the Eclipse IDE (eclipse.org), which I believe is also available for mac. So if you're a …

JasonHippy 739 Practically a Master Poster

Thats fantastic- thanks for that!

I haven't really looked into enums yet so I'll have to explore that once I start getting more than one manager ( because as I said these managers are singletons, so every element in my managers list will be of a different type.... I'll post if Ive got any queries on the enum method...


Thanks again,
PC_Nerd

EDIT: another question: can I use the run() method directly from the list, instead of creating that pointer to the object first?

Thanks

You mean something like myManager[0]->run(); ?
Yes, I think that might be possible...

However, thinking about it.. As all of these objects are singletons; to avoid having to mess around with dynamic casting, I suppose you could just put a public static GetInstance() method into each of your manager classes (if it's static then it can be called from outside of the class). The GetInstance function would then return a pointer to the instance of the required manager class.

If you know where each of the manager objects are in the list, then you could just reference the list item for each class and your GetInstance could return the pointer that way.

Actually, ignore all of that....You probably don't need the list at all come to think of it. You could perhaps store the instance pointers in each manager classes namespace and use a GetInstance function...

Something like this...
PingManager.h:

//headers, preprocessor, inclusion guards etc …
JasonHippy 739 Practically a Master Poster

ok - so this is my first even STL implementation (sort of)... so is this the sort of thing I'm looking for?

class Manager {
    protected:
        virtual int run(string msg);
}
class PingManager : public Manager {
    protected:
        int run(string msg) {
                std::cout << msg << std::endl;
                return 0;
       }
}

main() {
    PingManager ping;
    list<Manager> myManagers;
    myManagers.push_back(Manager* p &ping);
    .... later in my program
    Manager* mngr = dynamic_cast<Manager*>(myManagers[0]);
    mngr->run("my Message");
}

I'm just trying to make sure I'm understanding what is going on - as I've only just got my head around pointers and references ;)

Thanks for help!,
PC_Nerd

You've almost got it...At line 30 you'd need to do this though:

PingManager* mngr = dynamic_cast<PingManager*>(myManagers[0]);

because you'll be wanting to retrieve your pointer to your pingmanager.
and before calling mngr->run("My Message") you'd want to verify the pointer returned by the dynamic cast was not null! i.e.

if (mngr)
    mngr->run("My Message");

Once you've got several diffferent types of manager object defined and stored in your list, it could get a bit complicated as you may have to perform several dynamic casts before you get back to the original type.

Once it gets to that point, something you could consider doing is creating an enumeration of the different types of manager objects, create a std::pair consisting of your manager pointer and its associated enumeration and then store the pairs in the list. Then when you retrieve each pair, you check the enumerated value and then use …

JasonHippy 739 Practically a Master Poster

That sounds very helpful - if it werent for the fact I'm not sure what you mean by "dynamic cast" when I need to retreive the object back out again.

As their singletons I'll probably be storing pointers in there, and not the actual objects themselves.

Thanks heaps!!!!

No probs!
If you're storing pointers, then this certainly would be ideal.
To dynamically cast you use the dynamic_cast operator, there's shedloads of help on dynamic_cast on the web...Do a quick google and you'll find plenty of info!!

Basically it's a type-safe way of casting objects at runtime.
A successful cast will return a pointer to the chosen object type, but if a dynamic cast fails, it returns a null pointer..So if casting to one type fails, you can try casting it to a different type until you finally determine the objects type.

If memory serves correctly, I think you also need to ensure that the base class has at least one pure virtual function.

(Normally I would've included some code, but I'm not on my dev machine at the mo, so I don't have any relevant source code to refer to or pull up and copy/paste!)

Jas.

JasonHippy 739 Practically a Master Poster

Hi,

I'm trying to create an array or <list> of different objects ( of different type).

All of the objects will have parent objects of a Manager type, but each one ( as a singleton) will be in the array/list.

It's for some networking code I'm building, where each incoming message over the network is "given" to a manager - and the panager then acts on it ( or drops it if irrelevant)... so:

For each manager in manager_list:
manager_object->run(message);

sort of thing.


Is this possible/how could I achieve it, or what would an alternate model be?

Thanks,
PC_Nerd

Are all of the objects you wish to store derived from the same base class? If so you could try creating a standard library list (or deque or vector or whatever you feel is appropriate) containing objects of the base type...If you catch my drift??

e.g. You have a base class called ManagerObject, and several different types derived from ManagerObject,(I'll call them ManagerObjectTypeA, ManagerObjectTypeB, ManagerObjectTypeC.)

You could then create a std::list of ManagerObjects (std::list<ManagerObject>) which you could populate with anything derived from ManagerObject (in other words your ManagerObjectTypeA, B or C objects), as technically they are still ManagerObjects.

Then when it comes to retrieving the objects from the list, you'd have to dynamically cast them to determine their final type (i.e. whether they were type A, B or C).

I don't know if that is in any way helpful, or if it's quite …

JasonHippy 739 Practically a Master Poster

Hope I'm not too late on this one!
One other thing that you may have overlooked which could be making the difference is flash's local playback security settings.

What are your settings for local playback security?

Open up your source .fla and use ctrl + shift + F12 to access your publish settings (or click on "file->publish settings"). In the publish settings dialog, click on the flash tab and look for the "Local playback security" field at the bottom.

If you exported your .swf with it set to "Access Local Files Only", then that could very well be the cause of the problem.

If this is the case, try setting it to "Access network only", re-export your .swf and upload it to the appropriate place in your web-space. (Then try testing your web page again!)

I suspect this is most likely the case as the parameters you're passing to your movie in the html are URLS, so "Access network only" would seem more appropriate!

Other than that, I'm out of ideas.
If my above suggestion doesn't work and you're feeling patient, you could try loading your page (with the original flash file restored) and waiting for a while to see if your flash file is waiting for the whole video to be downloaded before it starts playing...Another possible reason for nothing appearing!

From what I can recall, the different security models were introduced some years ago to prevent flash apps/movies from …

JasonHippy 739 Practically a Master Poster

Hmm, I've been working on it again for 2 hours now...
this all I got... When I tried to print the puzzle array, it just display some random memory. I have no idea what seem to be the problem.

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed);

int main(int argc, char *argv[])
{
    int seed;
    int puzzle[ROWS][COLS];
    
    commandLineArguments(argc, argv, puzzle, seed);
    
    initPuzzle(puzzle, seed);
    
    cout << "vn : " << "(0 <= n <= 2) to move column n down 1 position" << "\n";
    cout << "hn : " << "(0 <= n <= 1) to move row n right 1 position" << "\n";
    cout << "i  : " << "to print these instructions" << "\n";
    cout << "q  : " << "to quit" << "\n";
    
    cout << puzzle;
    
    system("PAUSE");
    return 0;
}

void commandLineArguments(int argc, char *argv[], int puzzle[][COLS], unsigned int seed)
{
     if (argc != 2)
     {
          cout << "Please enter right number of argument";
     }
     
     &seed = atoi (argv[1]);
     
}

void movePuzzle(int puzzle[][COLS], char dir, int rowcol)
{
}

You can't cout a 2d array like that. You'll have to …

JasonHippy 739 Practically a Master Poster

Hey there, first up you need to decide exactly what you are going to be passing via the command line when the program is called..
i.e. perhaps you're going to call the program and pass the numbers to populate the array and the seed..
The numbers used are 1 to 6 and for the sake of argument, we'll use a seed of 45 which gives us a total of 7 parameters..

So for this example you'll end up calling the puzzle program passing 1 2 3 4 5 6 and 45 as parameters.

ok, thats all straightforward so far..

The purpose of your commandlinearguments function is to parse the arguments passed into the main function to try to extract the bits you want to use.

Personally I'd rename the commandlinearguments function to parseCommandLineArguments (cause that's what it's doing) and make it return a bool (to denote whether the parsing succeded or failed)....Alternatively, make it return an int and use 1 for success and 0 for failure!

So you'd have something like this:

/*****************************************************************************\
This is a C++ program that runs a puzzle game.
The puzzle consist of 2 row x 3 column grid.
Grid filled with numbers 1 to 6 in random order.

The main aim of this puzzle game is to get user swap those number so that
they are in order (with number 1 in top left and 6 in bottom right).
\*****************************************************************************/

#include "puzzle.h"

// NOTE: return type set …
JasonHippy 739 Practically a Master Poster

windns.h should probably be windows.h

That's another very viable possibility...I hadn't thought of that!
It could just be a typo!

JasonHippy 739 Practically a Master Poster

The answer is in all of the error messages you are recieving from the compiler.

C:\Documents and Settings\Visitor\Desktop\rx-asn-2-re-worked_v3\rx-asn-2-re-worked v3\includes.h(18) : fatal error C1083: Cannot open include file: 'windns.h': No such file or directory

What the compiler is telling you is that in "include.h" it cannot find the header file "windns.h" declared at line 18.

Either the windns.h file is missing, or the path to the file has been specified incorrectly in your source code (line 18 of include.h).

First make sure you can find the "windns.h" file.
If you don't have it, I guess you need to find/download a copy of it.

If this is a project that you've downloaded from the internet, it could be that the header file you require is a part of another SDK/API/library/project that is a dependancy of the project you are building.

If this is the case, check through any of the readme files / project documentation included with the project you're trying to build and see whether there are any other SDK's or libraries that are pre-requisites. If there are, make sure you have copies of them all.

Once you have the header, you either need to make a note of it's location and update line 18 of include.h to point to the correct location, or if the offending header is a part of another SDK/API/project you may want to update your project/compiler settings to include the include directory of the SDK and it's lib directory. …

JasonHippy 739 Practically a Master Poster

I made an application in Builder C++ 6.
It contains few graphic elements, few image lists. I use drawing on Canvas.
After short using my application, following message appears: "out of system resources". After it, my application behaves strangly and freezes. I use onPaint event.
My exe weights 2200 KB

From what you've said so far it sounds like the classic symptoms of a memory leak to me. The error message says it all!

The causes of memory leaks are not always glaringly obvious, but put in some breakpoints and step through your program and try to debug what is going on.
I'm sure you'll track it down eventually.

It's likely to be in a function that gets called often.
It could very well be something in your OnPaint() code.

The size of the final executable has no bearing on it's memory usage. Basically, what is happening is your program is allocating memory and never freeing/deleting it. Eventually your pc runs out of memory and your program is crashing.

There is no automatic garbage collection in C/C++, so any memory resources you allocate in your program must be freed.
You must ensure that 'delete' is called on any objects created using the 'new' keyword before they drop out of scope. Similarly any memory that has been allocated using alloc() or malloc() must be freed by a call to free().

Sometimes memory leaks can be the trickiest things in the …

JasonHippy 739 Practically a Master Poster

I'm not sure exactly what you're asking when you say
"can you tell me which style below function is showing in C++"

But I can answer the question in the topic title
"what is going on in this function?"

SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)
{   
    //Allocate userId
    m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();
    printf("Allocated for RNC, User Id=%d\n", m_UserId);
    //Allocate mtpSap
    m_MtpSapId = SmeConfigMgr::GetInstance()->GetFromFreeMtpSapIdPool();
    printf("Allocated for RNC, MTP SAP=%d\n", m_MtpSapId);
}

This line:

SmeConfigRnc::SmeConfigRnc(uint32_t rncId, uint16_t pc) : m_RncId(rncId), m_Pc(pc)

Is the constructor for a class called SmeConfigRnc.
The two parameters (rncId and pc) look as though they are user defined types (uint32_t and uint16_t) which are probably defined elsewhere using typedef statements.. (Otherwise they could be primitive types specific to the compiler being used to compile the program!)
Either way it looks as if they are a 32 bit unsigned integer and a 16 bit unsigned integer.

In the part of the constructor code which says:

: m_RncId(rncId), m_Pc(pc)

Two member variables ( m_RncId and m_Pc) are assigned the values passed into the constructor (i.e. the values of rncId and pc respectively)

The first line in the constructors body (after the comment):

m_UserId = SmeConfigMgr::GetInstance()->GetFromFreeUserIdPool();

This line is doing quite a lot.
SmeConfigMgr looks like it's probably a singleton (a class which can only have one instance in memory), the GetInstance() function will be a static member function of the SmeConfigMgr class which will return a pointer to …

William Hemsworth commented: Good post. +6
Comatose commented: Very Nice Description +8
StuXYZ commented: Nicely explained +3