Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 62 63 [64] 65 66 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100637 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #945 on: November 28, 2012, 09:30:46 am »

What's the error?
And what do you mean by MyGame being an abstract class?

Also, can anyone tell me why the code boxes look very small for me?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #946 on: November 28, 2012, 09:34:09 am »

Abstract class = cannot make an object out of it, since there are unoverriden virtual functions
But I can't see what I've missed.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #947 on: November 28, 2012, 09:48:53 am »

No, I meant (1) What's the error you're looking at? (2) What do you mean by MyGame being abstract? It seems pretty definite to me. To make it abstract, you need

virtual void function() = 0;, not virtual function() {}. The latter works perfectly fine being created as an object, while the former is purely abstract and cannot be defined.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #948 on: November 28, 2012, 10:15:02 am »

The error I'm looking at is "Error: Object of abstract class type "MyGame" is not allowed."
Do note that I'm inheriting from GameBase, which defines some pure virtual functions.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #949 on: November 28, 2012, 10:22:05 am »

Hmmm, I can't see where it goes wrong, either. Thing to Try: re-compiling everything (in case you do incremental compiling)? The fact that Base has a private con/destructor? Maybe it's actually the Position class where you declare but not define your methods?


Tip: Make the destructor of the parent class virtual. This will save you a TON of headaches later on. :P
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))

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #950 on: November 28, 2012, 10:51:10 am »

Oh wow, apparently I had a much deeper problem: I circularly #included files...
Works good so far, thanks.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #951 on: November 28, 2012, 11:40:31 am »

I already wondered why you commented out the #pragma once's....
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))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #952 on: November 30, 2012, 08:02:05 am »

Code: [Select]
1>c:\users\administrator\documents\visual studio 2010\projects\fermat-weber problem\fermat-weber problem\pvector.h(181): error C2244: 'pvector<pVectorType>::operator /' : unable to match function definition to an existing declaration
1>          definition
1>          'pvector<pVectorType> pvector<pVectorType>::operator /(Dividetype &)'
1>          existing declarations
1>          'pvector<pVectorType> pvector<pVectorType>::operator /(Dividetype &)'
Error from the compiler. Confounding me, because the definition and the declaration seem to be rather obviously identical.

@_@

Def:
Code: [Select]
template <class pVectorType>
class pvector
{
public:
/* other declarations not shown */
    template <class Dividetype>
  pvector<pVectorType> operator/ (Dividetype &var); //divide a pvector by a single var.

};

Dec:
Code: [Select]
template <class pVectorType, class Dividetype>
pvector<pVectorType> pvector<pVectorType>::operator/ (Dividetype &var)
{
pvector<pVectorType> result;
result.Coord.x /= var; // x/var
        result.Coord.y /= var; // y/var
        result.findLength(); //update the length variable
return result;
}

How it is used:
Code: [Select]
  for (int i = 0; i < xn.size(); i++)
    {
    topside = topside + xn.at(i) * cn.at(i) / xn.at(i).findDistance(y);
    bottomside = bottomside + cn.at(i) / xn.at(i).findDistance(y);
    }
topside = Emn = 1 ( xc / ||x - y||)
bottomside = Emn = 1 ( c / ||x - y||)

By the way, pvector<> is a templated class that has to do with physical vectors. In the final codebox, xn is a vector of pvector<double>, and y is a pvector<double>. For some reason, the overridden operator / doesn't work at all. :/ I think I'll have to just do it dirtily (by manipulating the basic variables directly) if no answer is found.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #953 on: November 30, 2012, 09:50:59 am »

Def:
Code: [Select]
template <class pVectorType>
class pvector
{
public:
/* other declarations not shown */
    template <class Dividetype>
  pvector<pVectorType> operator/ (Dividetype &var); //divide a pvector by a single var.

};

Dec:
Code: [Select]
template <class pVectorType, class Dividetype>
pvector<pVectorType> pvector<pVectorType>::operator/ (Dividetype &var)
{
pvector<pVectorType> result;
result.Coord.x /= var; // x/var
        result.Coord.y /= var; // y/var
        result.findLength(); //update the length variable
return result;
}

Move the deceleration into the definition, template functions are generated at compile so can't be defined the way you are. (or rather the template must be declared by point of instantiation).

Having said that the error your getting is poorly phrased if this is the problem.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #954 on: November 30, 2012, 09:54:04 am »

The definition an declaration are in the same header file, if that's wht you mean.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #955 on: November 30, 2012, 10:27:37 am »

The definition an declaration are in the same header file, if that's wht you mean.

I meant just include the function in the class def, but in the same header would achieve the same goal. The only other thing I can think of is that for some reason the pVectorType for the class def is different to the one in function call but I don't see how that could happen judging by the "how it is used" code segment.

I assume topside is the same type as the pVectorType of the cn elements?

What compiler are you using? as it isn't saying what the various types are in the error message.

Edit: if your using vs2005 there is a known bug (https://connect.microsoft.com/VisualStudio/feedback/details/724362/unable-to-match-function-definition), not sure if it's fixed in a released patch or just the later version of vs.
« Last Edit: November 30, 2012, 10:33:18 am by Shades »
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #956 on: November 30, 2012, 10:42:55 am »

Topside is pvector<double>. cn is vector<double>, xn is vector<pvector<double>>. y is also pvector<double>.
Though to be exact, since it's a template, they're all of pvector<T> and stuff.
I'm using VS2010. Maybe I should post the whole code tomorrow? Dx
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #957 on: November 30, 2012, 10:54:02 am »

Topside is pvector<double>. cn is vector<double>, xn is vector<pvector<double>>. y is also pvector<double>.
Though to be exact, since it's a template, they're all of pvector<T> and stuff.
I'm using VS2010. Maybe I should post the whole code tomorrow? Dx

I'd say try combing the defintion and declaration just in case that 2005 bug is still there, but it's marked as fixed so seems unlikely.
Feel free to post the code and I'll have a look (although probably not till Sunday)

I don't suppose findDistance is a templated function too? Looks to me that the operation should collapse down to using the divisor for whatever type findDistance returns, although whatever that is as long as the coord.x and .y can be divided by it it should be fine, and if it couldn't I'd expect a different error.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #958 on: November 30, 2012, 11:11:46 am »

Code: [Select]
template <class pVectorType>
template <class Dividetype>
pvector<pVectorType> pvector<pVectorType>::operator/ (Dividetype &var)
{
pvector<pVectorType> result;
result.Coord.x /= var; // x/var
        result.Coord.y /= var; // y/var
        result.findLength(); //update the length variable
return result;
}
Could also try that. (just broken the definition so class and function templates are separate, I learnt something new today thanks :))

(taken from: http://www.comeaucomputing.com/techtalk/templates/#outsidedef)
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

olemars

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #959 on: November 30, 2012, 11:12:23 am »

Def:
Code: [Select]
template <class pVectorType>
class pvector
{
public:
/* other declarations not shown */
    template <class Dividetype>
  pvector<pVectorType> operator/ (Dividetype &var); //divide a pvector by a single var.

};

Dec:
Code: [Select]
template <class pVectorType, class Dividetype>
pvector<pVectorType> pvector<pVectorType>::operator/ (Dividetype &var)
{
pvector<pVectorType> result;
result.Coord.x /= var; // x/var
        result.Coord.y /= var; // y/var
        result.findLength(); //update the length variable
return result;
}

Instead of
Code: [Select]
template <class pVectorType, class Dividetype>
do
Code: [Select]
template <class pVectorType> template <class Dividetype>
like the ninja suggests.
Logged
Pages: 1 ... 62 63 [64] 65 66 ... 91