Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 135 136 [137] 138 139 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 906751 times)

DJ

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2040 on: March 25, 2012, 01:50:20 pm »

Whee, another issue! ifstream isn't opening test.txt that is in the same folder as the exe (ie project/debug). I know because debugger tells me that tststrm.is_open() evaluates to false. Full code:
Spoiler (click to show/hide)
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2041 on: March 25, 2012, 07:11:17 pm »

Try not running it through the visual studio run option, but by manually launching the executable. If this works, check the running directory in the project settings. I'm pretty sure Visual Studio defaults to the project directory, not the directory the executable is in, which means as far as the program is concerned the "root" is not ./project/debug but ./project
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2042 on: March 25, 2012, 08:28:25 pm »

I see one potential issue immediately. The program is running in the sprite namespace. Does that namespace automatically include everything from the std namespace? If not, that could cause some weird things to happen. Try instead:

Code: [Select]
#include "SDL Sprite.h"
#include <stdio.h>

using namespace std;

sprite::Sprite* test;
int test_fun();

int main(int arcg, char **argv)
{
   /*string teststr = "test.txt";
   vector<string> testarg;
   testarg.push_back(teststr);
   test = new sprite::Sprite(teststr);*/
   ifstream tststrm;
   tststrm.open("test.txt", ios::in);
   if(tststrm.is_open()) cout << "Great success!";
   tststrm.close();
   return 0;
}

Another thing you could try is using the constructor for ifstream that opens the file upon construction:

Code: [Select]
ifstream tststrm("text.txt", ios::in);

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2043 on: March 26, 2012, 08:57:00 am »

*sigh* Switching from coding on Linux to Windows only to discover that the windows build of gcc does not have thread support and boost isn't exactly a "drop-in" replacement yet for things like condition_variable.

C++11 uses a sleep_until, sleep_for, wait_until, wait_for approach to timed waits and sleeps, whilst boost still has timed_wait and sleep.

C++11 wait_for and wait_until return cv_status, timed_wait returns a boolean.

C++11 uses std::chrono whilst boost still uses boost::datetime, at least until 1.49.0 is finished.

I wrote a very hackish way around, basically inheriting from the incompatible boost types and adding the functions I was using that boost doesn't have, converting the timepoint or duration to a boost ptime.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2044 on: March 26, 2012, 01:49:30 pm »

Grah. I'm out of things to fix to get rid of this error:

Quote from: g++ -o a.o a.cpp
a.cpp: In constructor ‘a::a(int, bInterface*, bInterface*)’:
a.cpp:5:82: error: no matching function for call to ‘aInterface::aInterface()’
fwd.h:13:5: note: candidates are: aInterface::aInterface(int, bInterface*, bInterface*)
fwd.h:11:26: note:                 aInterface::aInterface(const aInterface&)

Code: [Select]
//a.h
#ifndef ENDOWMENTS_H_INCLUDED
#define ENDOWMENTS_H_INCLUDED

#include "a_util.h" // includes typedefs and consts that represent various things irrelevant to the error
#include "fwd.h"

class a : public aInterface {
    int type;
    int value;
    bInterface* other1;
    bInterface* other2;
public:
    a(int t, bInterface* o1, bInterface* o2);
    // other functions not relevant to the error
};
#endif // ENDOWMENTS_H_INCLUDED

Code: [Select]
// a.cpp
#include "a.h"

using namespace std;

a::a(int t, bInterface* o1, bInterface* o2) {
    type = t;
    other2 = o1;
    other2 = o2;
    value = other2->getValue(type);
}

// definitions for other functions not relevant to the error

Code: [Select]
// fwd.h
#ifndef FWD_H_INCLUDED
#define FWD_H_INCLUDED

#include <string>
#include "a_util.h"

using namespace std;

class bInterface;

class aInterface {
public:
    aInterface(int t, bInterface* o1, bInterface* o2);
    // virtual functions to be overriden by a
};

class bInterface {
public:
    bInterface(string n, int attr[]=NULL); // Pre: if not null, attr is length 10
    // virtual functions to be overriden by b
};

#endif // FWD_H_INCLUDED

Any suggestions? It seems that, in the constructor for a, the default constructor is somehow getting called, but I don't see where.

Note to self: never ever ever try a project that requires codependent classes again.
« Last Edit: March 26, 2012, 02:10:43 pm by Mego »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2045 on: March 26, 2012, 01:53:21 pm »

Code: [Select]
a::a(int t, bInterface* o1, bInterface* o2) : aInterface(t, o1, o2) {
    type = t;
    other2 = o1;
    other2 = o2;
    value = other2->getValue(type);
}

Or... your aInterface constructor name in the aInterface class is actually bInterface.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2046 on: March 26, 2012, 02:13:50 pm »

Code: [Select]
a::a(int t, bInterface* o1, bInterface* o2) : aInterface(t, o1, o2) {
    type = t;
    other2 = o1;
    other2 = o2;
    value = other2->getValue(type);
}

Or... your aInterface constructor name in the aInterface class is actually bInterface.

It seems I messed that up when I transferred the code from the project to here. a(Interface) and b(Interface) are not the classes' actual names in the project. I changed them for simplicity (or so I thought).

The first suggestion you made wouldn't work, because the constructor for aInterface is not defined, only declared (same goes for bInterface). There will never be any aInterface or bInterface objects in the code; only a and b object pointers pretending to be aInterface and bInterface object pointers.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2047 on: March 26, 2012, 02:19:53 pm »

If C inherits from A and B, A and B need to have defined constructors called by C in C's constructors (and if you don't specify, A() and B() get called automatically). Make them protected but define them if you want C to access them but don't want to be able to construct A or B by itself.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2048 on: March 26, 2012, 03:06:25 pm »

When did multiple inheritance come into play? Anyways, I do not want default constructors for these classes. I have not defined any. Why one is even appearing in the error is beyond me.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2049 on: March 26, 2012, 03:12:07 pm »

When did multiple inheritance come into play? Anyways, I do not want default constructors for these classes. I have not defined any. Why one is even appearing in the error is beyond me.

And by and I of course meant or *d'oh*

The problem is in constructor ‘a::a(int, bInterface*, bInterface*)', it is trying to call the default constructor for aInterface. Column 5, line 82 I believe. As it isn't finding the default constructor, error.
« Last Edit: March 26, 2012, 03:17:33 pm by MorleyDev »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2050 on: March 26, 2012, 03:19:16 pm »

Yes, I think you either need an empty default constructor for the interface, or define and call the one with parameters. C++ just "fakes" interfaces, it's really just inheritance, and not specifying the constructor of the parent makes it call the default "empty" one. What Morley said: make them protected if it makes you feel dirty.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2051 on: March 26, 2012, 03:40:52 pm »

If you don't declare any custom constructors the compiler will add a default constructor for you. So your code would have worked if you removed your undefined constructors.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2052 on: March 26, 2012, 04:22:10 pm »

The thing is, I did declare custom constructors, both in the interface class and the implementation class. I didn't define the constructor in the interface class. That is the only reason I can see for having the compiler try to make a default constructor.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2053 on: March 26, 2012, 05:11:47 pm »

It only makes one if you didn't. Right now you did, so it won't, but it will still try to call aInterface::aInterface() when it is trying to construct "a".
Solutions:
- removing the constructor from the interface
- defining the constructor in the interface and explicitly call it

See here as well: http://ubuntuforums.org/showthread.php?t=171946
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2054 on: March 26, 2012, 05:55:59 pm »

Hook one of these (http://www.arduino.cc/) up to a mechanized club and a speaker and I'll write a program that beats you over the head to remind you to learn to program!
Logged
Pages: 1 ... 135 136 [137] 138 139 ... 796