Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Class uses RenderWindow but can't use base constructor?  (Read 6691 times)

0 Members and 1 Guest are viewing this topic.

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Class uses RenderWindow but can't use base constructor?
« on: August 16, 2011, 10:52:46 pm »
I have a class that inherits public properties from sf::RenderWindow. What's wrong with it if it can't use basic constructor's like the 2 argument sf::VideoMode, string one?

Also i'm about to peak at the RenderWindow.cpp source code, but doesn't anyone know if I can just make my own constructor like that and use the variables used in the orig. constructor etc. Basically make a copy... but I still don't know why the first one wouldn't work if i'm using it correctly. Also this is my only error in compiling this one header with three source files.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Class uses RenderWindow but can't use base constructor?
« Reply #1 on: August 16, 2011, 11:12:38 pm »
Quote from: "KasHKoW"
What's wrong with it if it can't use basic constructor's like the 2 argument sf::VideoMode, string one?
Could you describe the problem more clearly? What doesn't work exactly? Please provide a short code.

Same for the other problem, I don't understand your description ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Class uses RenderWindow but can't use base constructor?
« Reply #2 on: August 17, 2011, 12:30:22 am »
hpp file
Code: [Select]

class _2deWindow : public sf::RenderWindow {
//couple variables
public:
//couple functions
};


source file
Code: [Select]

_2de::_2deWindow App(sf::VideoMode(800,600,32), "Boundaries Test");


error
Quote

BoundTests.cpp: In function β€˜int main()’:
BoundTests.cpp:8: error: no matching function for call to β€˜_2de::_2deWindow::_2deWindow(sf::VideoMode, const char [16])’
_2de.hpp:51: note: candidates are: _2de::_2deWindow::_2deWindow()
_2de.hpp:45: note:                 _2de::_2deWindow::_2deWindow(const _2de::_2deWindow&)


I have no constructors what so ever. As you can see, which I just noticed, it's noticing it as a function which is weird.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Class uses RenderWindow but can't use base constructor?
« Reply #3 on: August 17, 2011, 12:42:43 am »
Constructors are not inherited. You have to write your own, and forward the arguments to the base class via initializer list.

This should be explained in your C++ book...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Class uses RenderWindow but can't use base constructor?
« Reply #4 on: August 17, 2011, 02:13:10 am »
I haven't read one. I don't really plan on it either.

They kind of turn me off from coding. I want to read effective c++/accelerated c++, but I really haven't got the time. I'm using cprogramming.com && cplusplus.com's tutorials which are pretty nice.

Haikarainen

  • Guest
Class uses RenderWindow but can't use base constructor?
« Reply #5 on: August 17, 2011, 05:40:24 am »
Code: [Select]
class _2deWindow : public sf::RenderWindow {
public:
_2deWindow(sf::VideoMode a, std::string title):sf::RenderWindow(a,title){}
};


Something like that should work

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Class uses RenderWindow but can't use base constructor?
« Reply #6 on: August 17, 2011, 09:55:05 am »
I think books are really worth the time, you can't learn C++ effectively by internet tutorials. At least I haven't seen one that covers C++ deeply enough and that doesn't neglect important background information.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Class uses RenderWindow but can't use base constructor?
« Reply #7 on: August 17, 2011, 01:58:32 pm »
Quote from: "KasHKoW"
I haven't read one. I don't really plan on it either.

They kind of turn me off from coding. I want to read effective c++/accelerated c++, but I really haven't got the time. I'm using cprogramming.com && cplusplus.com's tutorials which are pretty nice.
I'd recommend trying one, I started with Beginning C++ Game Programming, it's essentially just a C++ beginners book disguised as game coding.

I noticed that I improved and learnt at a much faster rate after swapping to books compared to doing online tutorials. At the very least it's easier than alt-tabbing to compare your code with the examples.

But at least you've already found cplusplus.com, I think it's the best online reference available. Keep it handy when dealing with the STL.  :D

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Class uses RenderWindow but can't use base constructor?
« Reply #8 on: August 17, 2011, 02:07:10 pm »
Quote from: "Nexus"
I think books are really worth the time
Yes, absolutely! Take this advice seriously into consideration. Moreover, AC++ is a very good book (good example, good approach, etc..)

Quote
cplusplus.com, I think it's the best online reference available.
gloups (ok, it isn't the point of the discussion but...)
SFML / OS X developer

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Class uses RenderWindow but can't use base constructor?
« Reply #9 on: August 17, 2011, 02:38:06 pm »
Quote from: "Hiura"
gloups (ok, it isn't the point of the discussion but...)
Oh wow. Thanks for that, I redact my earlier statement. And now I have to go hunting for a new reference site.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Class uses RenderWindow but can't use base constructor?
« Reply #10 on: August 17, 2011, 04:17:15 pm »
I would recommend this one if you're not afraid of raw stuff : http://www.dinkumware.com/manuals/#Standard%20C++%20Library . It's not the easiest, I agree, but it seems complete and correct (I never heard of problem on this reference site to be precise).
SFML / OS X developer

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Class uses RenderWindow but can't use base constructor?
« Reply #11 on: August 17, 2011, 04:23:55 pm »
Yeah The books I was reading was Game Programming All in One third edition; Accelerated C++; cplusplus.com C++ Language Tutorial for quick reference. I haven't completely finished any of them yet. The first two not even close lol. I might start looking at them little by little now.


EDIT: I will take a look at that one.

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Class uses RenderWindow but can't use base constructor?
« Reply #12 on: August 17, 2011, 07:05:03 pm »
Quote from: "thePyro_13"
I noticed that I improved and learnt at a much faster rate after swapping to books compared to doing online tutorials. At the very least it's easier than alt-tabbing to compare your code with the examples.

But at least you've already found cplusplus.com, I think it's the best online reference available. Keep it handy when dealing with the STL.  :D


I've learned the fastest by simply using tutorials writing code, reading others code, and doing major refactoring implementing a bunch of new ways that just did the same stuff as the old ways faster and better with conciseness in mind.

also learning a new language, but not even writing in it, can augment your currently known and in use languages a lot.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Class uses RenderWindow but can't use base constructor?
« Reply #13 on: August 17, 2011, 07:24:31 pm »
One problem with cplusplus.com is also that it contains no information about C++0x nor the TR1. I have mostly used MSDN to lookup library features of the new C++ standard, although the navigation on the site is not the best one.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Class uses RenderWindow but can't use base constructor?
« Reply #14 on: August 18, 2011, 04:03:35 am »
Quote from: "Haikarainen"
Code: [Select]
class _2deWindow : public sf::RenderWindow {
public:
_2deWindow(sf::VideoMode a, std::string title):sf::RenderWindow(a,title){}
};


Something like that should work


That's really nice. I thought I understood how it worked but now I'm confused.. The single colon ":sf::RenderWindow(...)...{}" part is confusing. did you mean a comma and to keep it in the first list or arguments or is that a feature I'm not even aware of?