Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
P

Patrick G

@Patrick G
About
Posts
11
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Class definition issue
    P Patrick G

    Thanks for the tip, you were correct. Now I get to go back to recreating my real problem... the phantom access violation!

    C / C++ / MFC help career workspace

  • Class definition issue
    P Patrick G

    Hello, I'm trying to recreate a problem that I'm having in another project and have created a small overly simple project to experiment with. That being said, I'm being blocked by what seems like a really silly problem. So, I have two classes: ClassA and ClassB. ClassB's constructor takes a pointer to ClassA as a parameter for later use. The compiler seems not to mind that, however it does not like when I try to use the pointer that is passed. Here's some code:

    //ClassA.h
    #pragma once;

    #include <iostream>
    using namespace std;

    #include "ClassB.h"
    class ClassB;

    class ClassA {
    public:
    ClassA () {
    this->b = new ClassB(this);
    }

    void printer() {
    	cout << "Hello world from A!\\n";
    }
    

    private:
    ClassB* b;

    };

    And a little more:

    //ClassB.h
    #pragma once;

    #include <iostream>
    using namespace std;

    #include "ClassA.h"
    class ClassA;

    class ClassB {
    public:
    ClassB(ClassA *a) {
    this->ca = a;
    cout << "Constructor B \n\n";
    ca->printer();
    }

    private:
    ClassA *ca;
    };

    and finally a main to polish it off:

    #include <windows.h>

    #include <iostream>
    using namespace std;

    #include "ClassA.h"
    #include "ClassB.h"

    void main() {
    ClassA a;
    Sleep(10000);
    }

    I get two errors with this setup. They both point to ca->printer(); in the ClassB.h file. They are Error 1 error C2027: use of undefined type 'ClassA' classb.h 14 and Error 2 error C2227: left of '->printer' must point to class/struct/union/generic type classb.h 14 . Oddly enough, this isn't even the problem I'm trying to recreate from my larger project (I don't have this problem there). I'm actually trying to recreate an access violation on the call to the constructor of the class that ClassB represents (then the program continues, but it never executes the constructor). Anyway, I'll settle for figuring out what the silly mistake I'm making is that's blocking the compiler from finishing the job. Thanks for your help!

    C / C++ / MFC help career workspace

  • how do i know the number of messages left unprocessed in a message queue?
    P Patrick G

    I must admit, I havn't used the Microsoft queue, but I have used my own queues as well as queues written for POSIX in Linux. Typically, I've found that there is a length() method on the queue class. In the searches that I just ran I can't say that I've found this to be the case for Microsoft, but I did notice a few methods that could be used to cobble something up with from here: http://msdn.microsoft.com/en-us/library/ms699810(VS.85).aspx[^]. A few ideas that came to mind as I was reading this (unfortunately none of them are as elegant as a getLength() method). One idea that could work is to EnableNotification() and then to have your own counter that increments when a message is received and decrements when a message is used. Another is to use repeated calls to the PeekNext() method in a loop, counting the number of elements in the queue as you go. Sorry I couldn't be more insightful for you. I hope that what I've found helps you set up an algorithm to get your program working the way you want it to.

    C / C++ / MFC question data-structures

  • Extending a class that uses a template
    P Patrick G

    Sorry, I should have posted that with my original code. I assume you're referring to the first example. This was the call to the mutator acceptor.setCommSystem(commSystem);. The previous lines of code are initializations for other classes that are irrelevant to this problem with the exception of the call to the constructor just prior to this. That was SocketAcceptor acceptor(svs, reactor); Here's a little summary of the files so that this all makes more sense. ReactorServer is the class that is trying to declare a ReactorServiceHandler which uses the template. CommunicationSystem* comms (or commSystem, depending on where you read it in the post) is just a pointer to an object that manages these objects (among others) that deal with communications. (It's similar to the Facade design pattern).

    C / C++ / MFC help question

  • Extending a class that uses a template
    P Patrick G

    Led Mike, I'm sorry if you didn't like me voting your response as not useful, but since it wasn't an answer, I'm afraid it really wasn't useful. That being said, I do appreciate any assistance. Also, I appreciate that people do in take the time to read and help other people out with their problems. Now, with all of that being said, in my (very long) experience with C++ compilers I've found that when the compiler gets confused it tends to spit out trash for error messages. You mentioned that the errors are "novice" mistakes (since they are referring to semicolons and such). I guarantee that there are no semicolons missing. I know this because when I take out my function calls (listed above, semicolons and all) all the troubles go away. (I should point out that in example 2 I forgot to post the deceleration of my private member variable, it is in the code though, as in example 1). Also, as in the code shown above, the variables that are claimed by the compiler to not be declared in fact are, but seem to be ignored by the compiler. This is actually why I didn't give any errors in my first post and why I only summarized the problem (I figured a print out of nonsensical compiler errors would be a waste of disk space). All of this led me to believe that when a class uses a template that it can't have additional parameters added to it lightly, although I highly doubt that it's impossible.

    C / C++ / MFC help question

  • Extending a class that uses a template
    P Patrick G

    Context: I want to have a pointer to an object as a member of a class that uses a template. All the errors I show below point to the lines of code that I've provided. Example 1: Add a private parameter and change it using a public mutator. Here's the private parameter: CommunicationSystem* comms; Here's the mutator declaration: void setCommSystem(CommunicationSystem* commSystem); Here's the implementation of the mutator:

    void ReactorServiceHandler::setCommSystem(CommunicationSystem* commSystem) {
    this->comms = commSystem;
    }

    Here's the call of the mutator: acceptor.setCommSystem(commSystem); Note it doesn't much matter if I use the "." or the "->", I get identical errors. Here's 9 errors complaining about it:

    Error 1 error C2039: 'setCommSystem' : is not a member of 'Poco::Net::SocketAcceptor' c:\Documents and Settings\patrick\My Documents\VirtualWorld\Cave\src\ReactorServer.cpp 125
    Error 2 error C2061: syntax error : identifier 'CommunicationSystem' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 94
    Error 3 error C2143: syntax error : missing ';' before '*' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
    Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
    Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
    Error 6 error C2061: syntax error : identifier 'CommunicationSystem' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 94
    Error 7 error C2143: syntax error : missing ';' before '*' c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
    Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105
    Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\patrick\my documents\virtualworld\cave\include\ReactorServiceHandler.h 105

    Switching the parameter from private to public and getting ri

    C / C++ / MFC help question

  • Extending a class that uses a template
    P Patrick G

    I'm needing to add functionality to a class that uses a template. In other words, there is a template class in a library that I'm using, I need to use it (there is no escaping it), but I really need to pass an additional parameter to it either via constructor (my preferred solution) or by using a mutator method. The problem is that the compiler refuses to allow me to do two things: 1) add a parameter to the class, and 2) add a parameter to a constructor or add a new method to my class. Is there a 'proper' way to do this?

    C / C++ / MFC help question

  • how do i know the number of messages left unprocessed in a message queue?
    P Patrick G

    This depends on the implementation of the message queue. If you have a message queue class, perhaps there is a getQueueLength() method? Or, if it's implemented similarly to a C string, perhaps there is a terminator at the end of an array? There is always a brute force approach, iterate through every element and count it, but this is not what I would call a good solution. On that note, to give you a good answer, you need to post more information about what you're doing.

    C / C++ / MFC question data-structures

  • Multiple Inheritance Problem [modified]
    P Patrick G

    I found the reason for the problem -> There was an unresolvable ambiguity (the compiler couldn't tell which base class to override. Here's what Stroustrup has to say about this issue (see page 5). http://www-plan.cs.colorado.edu/diwan/class-papers/mi.pdf[^] Thanks for your responses. I must admit, I'm curious how you all got it to work. To solve the problem, I ended up writing a wrapper class... please excuse my sad attempt at ASCII art, but here's the UML behind how I solved it.

    ----------- -----------
    | Class A | | Class B |


    /\\                     /\\
    --                     --
     |                      |
     |                      |
    

    | MyClass |_________/\| MyWrapper |
    ----------- \/-------------

    C / C++ / MFC help design oop question

  • Multiple Inheritance Problem [modified]
    P Patrick G

    Sorry about that typo, that's the "real" name of MyClass (my program is for a reactor server in a distributed system). The should say

    MyClass::run()

    . Also, I declare the classes in h files and code them in cpp files separately, which is why I have that there in the first place.

    C / C++ / MFC help design oop question

  • Multiple Inheritance Problem [modified]
    P Patrick G

    Hello! I have a bit of an odd problem. I'm writing some code that pulls functionality from two different APIs. I also, for what I'm trying to do, I need to inherit from two abstract classes, however I have a bit of a problem... both abstract classes have a method by the same name (but with a different return type), and of coarse, one of them is virtual and I'm trying to overwrite it. The other class does not have this method as virtual, and I am not at all interested in overwriting it. Here's what I'm describing in terms of code...

    class BaseA {
    int run(int argc, char** argv) {
    // insert some code
    }
    };

    class BaseB {
    virtual void run() = 0;
    };

    class MyClass: public BaseA, BaseB {
    void ReactorServer::run() { // Overwrite the virtual method in BaseB (which has nothing to do with BaseA)
    // My code here
    }
    }

    The problem is that the comiler complains with the following: Error 1 error C2555: 'MyClass::run': overriding virtual function return type differs and is not covariant from 'BaseA::run' c:\Documents and Settings\patrick\MyClass.h 126 which indicates to me that the compiler is trying to overwrite the method in BaseA and not BaseB. I've tried putting "virtual" in front of my declaration without success. This also bothers me from the perspective that this is a bit of a "smelly" design issue as well, but at the moment I don't think I have a choice because I need these Base Classes! Any suggestions? Thank you Patrick

    modified on Friday, July 4, 2008 2:27 PM

    C / C++ / MFC help design oop question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups